Skip to content

Commit

Permalink
Merge pull request #557 from axonivy/format
Browse files Browse the repository at this point in the history
Format and Clean up Java source code as defined in ADR-029
  • Loading branch information
ivy-cst authored Dec 31, 2024
2 parents a642587 + 09d3018 commit ad7ab60
Show file tree
Hide file tree
Showing 60 changed files with 455 additions and 480 deletions.
12 changes: 5 additions & 7 deletions src/main/java/ch/ivyteam/ivy/maven/AbstractEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ public abstract class AbstractEngineMojo extends AbstractMojo {
/** testing only: avoid restriction to minimal version! */
boolean restrictVersionToMinimalCompatible = true;

public AbstractEngineMojo() {
super();
}
public AbstractEngineMojo() {}

/**
* <b style="color:red">Caution</b>: normally you should favor
Expand Down Expand Up @@ -169,14 +167,14 @@ protected final VersionRange getIvyVersionRange() throws MojoExecutionException
}

private VersionRange restrictToMinimalCompatible(VersionRange ivyVersionRange)
throws InvalidVersionSpecificationException, MojoExecutionException {
throws InvalidVersionSpecificationException, MojoExecutionException {
VersionRange minimalCompatibleVersionRange = VersionRange
.createFromVersionSpec("[" + AbstractEngineMojo.MINIMAL_COMPATIBLE_VERSION + ",)");
.createFromVersionSpec("[" + AbstractEngineMojo.MINIMAL_COMPATIBLE_VERSION + ",)");
VersionRange restrictedIvyVersionRange = ivyVersionRange.restrict(minimalCompatibleVersionRange);
if (!restrictedIvyVersionRange.hasRestrictions()) {
throw new MojoExecutionException(
"The ivyVersion '" + ivyVersion + "' is lower than the minimal compatible version"
+ " '" + MINIMAL_COMPATIBLE_VERSION + "'.");
"The ivyVersion '" + ivyVersion + "' is lower than the minimal compatible version"
+ " '" + MINIMAL_COMPATIBLE_VERSION + "'.");
}
return restrictedIvyVersionRange;
}
Expand Down
31 changes: 15 additions & 16 deletions src/main/java/ch/ivyteam/ivy/maven/IarPackagingMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,15 @@
public class IarPackagingMojo extends AbstractMojo {
public static final String GOAL = "pack-iar";

public static interface Defaults {
String[] INCLUDES = new String[] {"**/*"};
String[] EXCLUDES = new String[] {"target/"};
String[] TARGET_INCLUDES = new String[] {
"target/classes/**/*",
"target/src_hd/**/*"
public interface Defaults {
String[] INCLUDES = {"**/*"};
String[] EXCLUDES = {"target/"};
String[] TARGET_INCLUDES = {
"target/classes/**/*",
"target/src_hd/**/*"
};
}


@Parameter(property = "project", required = true, readonly = true)
MavenProject project;

Expand All @@ -68,8 +67,8 @@ public static interface Defaults {
* Sample:
* <pre>
* <code>&lt;iarExcludes&gt;
* &lt;iarExclude&gt;target/com/acme/scret/*&lt;/iarExclude&gt;
* &lt;iarExclude&gt;src/&lt;/iarExclude&gt;
* &nbsp;&nbsp;&lt;iarExclude&gt;target/com/acme/scret/*&lt;/iarExclude&gt;
* &nbsp;&nbsp;&lt;iarExclude&gt;src/&lt;/iarExclude&gt;
* &lt;/iarExcludes&gt;</code>
* </pre>
*/
Expand All @@ -84,13 +83,13 @@ public static interface Defaults {
* See {@link ch.ivyteam.ivy.maven.IarPackagingMojo.Defaults#TARGET_INCLUDES}.
*
* <pre>
* <code>&lt;iarFileSets&gt;
* &lt;iarFileSet&gt;
* &lt;includes&gt;
* &lt;include&gt;**&#47;*&lt;/include&gt;
* &lt;/includes&gt;
* &lt;/iarFileSet&gt;
*&lt;/iarFileSets&gt;</code>
* &lt;iarFileSets&gt;
* &nbsp;&nbsp;&lt;iarFileSet&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;includes&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;include&gt;**&#47;*&lt;/include&gt;
* &nbsp;&nbsp;&nbsp;&nbsp;&lt;/includes&gt;
* &nbsp;&nbsp;&lt;/iarFileSet&gt;
* &lt;/iarFileSets&gt;
* </pre>
*/
@Parameter
Expand Down
26 changes: 13 additions & 13 deletions src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public class InstallEngineMojo extends AbstractEngineMojo {
* </p>
*
* <pre>
* groupId=com.axonivy.ivy
* artifactId=engine
* version=!ivyVersion! (e.g. 7.4.0)
* classifier=!osArchitecture! (e.g. Slim_All_x64)
* extension=zip
* groupId=com.axonivy.ivy
* artifactId=engine
* version=!ivyVersion! (e.g. 7.4.0)
* classifier=!osArchitecture! (e.g. Slim_All_x64)
* extension=zip
* </pre>
*
* @since 7.4
Expand Down Expand Up @@ -185,7 +185,7 @@ private void handleNoInstalledEngine() throws MojoExecutionException {

private void handleWrongIvyVersion(ArtifactVersion installedEngineVersion) throws MojoExecutionException {
getLog().info("Installed engine in '" + getRawEngineDirectory() + "' has version '"
+ installedEngineVersion + "' instead of expected '" + ivyVersion + "'");
+ installedEngineVersion + "' instead of expected '" + ivyVersion + "'");
boolean cleanEngineDir = installedEngineVersion != null;
downloadAndInstallEngine(cleanEngineDir);
}
Expand Down Expand Up @@ -223,30 +223,30 @@ private void downloadAndInstallEngine(boolean cleanEngineDir) throws MojoExecuti
ArtifactVersion installedEngineVersion = getInstalledEngineVersion(getRawEngineDirectory());
if (installedEngineVersion == null) {
throw new MojoExecutionException(
"Can not determine installed engine version in directory '" + getRawEngineDirectory() + "'. "
+ "Possibly a non-OSGi engine.");
"Can not determine installed engine version in directory '" + getRawEngineDirectory() + "'. "
+ "Possibly a non-OSGi engine.");
}
if (!getIvyVersionRange().containsVersion(installedEngineVersion)) {
throw new MojoExecutionException("Automatic installation of an ivyEngine failed. "
+ "Downloaded version is '" + installedEngineVersion + "' but expecting '" + ivyVersion
+ "'.");
+ "Downloaded version is '" + installedEngineVersion + "' but expecting '" + ivyVersion
+ "'.");
}
} else {
throw new MojoExecutionException("Aborting class generation as no valid ivy Engine is available! "
+ "Use the 'autoInstallEngine' parameter for an automatic installation.");
+ "Use the 'autoInstallEngine' parameter for an automatic installation.");
}
}

public EngineDownloader getDownloader() throws MojoExecutionException {
if (downloadUsingMaven) {
return new MavenEngineDownloader(getLog(), ivyVersion, osArchitecture, pluginRepositories,
repositorySystem, repositorySession);
repositorySystem, repositorySession);
}

@SuppressWarnings("deprecation")
ProxyInfoProvider proxies = wagonManager::getProxy;
return new URLEngineDownloader(engineDownloadUrl, engineListPageUrl, osArchitecture, ivyVersion,
getIvyVersionRange(), getLog(), getDownloadDirectory(), proxies);
getIvyVersionRange(), getLog(), getDownloadDirectory(), proxies);
}

static String ivyEngineVersionOfZip(String engineZipFileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
var sourceEncoding = properties.get(PROJECT_BUILD_SOURCEENCODING);
if (sourceEncoding != null) {
getLog().info("'" + PROJECT_BUILD_SOURCEENCODING + "' is already set to '" +
sourceEncoding + "', so it will not be overwritten to UTF-8");
sourceEncoding + "', so it will not be overwritten to UTF-8");
return;
}
getLog().info("Set '" + PROJECT_BUILD_SOURCEENCODING + "' to UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public abstract class AbstractEngineInstanceMojo extends AbstractEngineMojo {

private static MavenProjectBuilderProxy builder;

public AbstractEngineInstanceMojo() {
super();
}
public AbstractEngineInstanceMojo() {}

@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
Expand All @@ -84,11 +82,11 @@ protected MavenProjectBuilderProxy getMavenProjectBuilder() throws Exception {
var engineDir = identifyAndGetEngineDirectory();
if (builder == null) {
builder = new MavenProjectBuilderProxy(
classLoaderFactory,
toFile(buildApplicationDirectory),
toFile(engineDir),
getLog(),
timeoutEngineStartInSeconds);
classLoaderFactory,
toFile(buildApplicationDirectory),
toFile(engineDir),
getLog(),
timeoutEngineStartInSeconds);
}
classLoaderFactory.writeEngineClasspathJar(engineDir);
// share engine directory as property for custom follow up plugins:
Expand All @@ -104,8 +102,8 @@ private File toFile(Path path) {

public final EngineClassLoaderFactory getEngineClassloaderFactory() {
MavenContext context = new EngineClassLoaderFactory.MavenContext(
repository, localRepository, project, getLog());
repository, localRepository, project, getLog());
return new EngineClassLoaderFactory(context);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public abstract class AbstractProjectCompileMojo extends AbstractEngineInstanceM
protected Map<String, Object> getOptions() {
Map<String, Object> options = new HashMap<>();
options.put(MavenProjectBuilderProxy.Options.TEST_SOURCE_DIR,
project.getBuild().getTestSourceDirectory());
project.getBuild().getTestSourceDirectory());
options.put(MavenProjectBuilderProxy.Options.COMPILE_CLASSPATH, getDependencyClasspath());
options.put(MavenProjectBuilderProxy.Options.SOURCE_ENCODING, encoding);
options.put(MavenProjectBuilderProxy.Options.WARNINGS_ENABLED, Boolean.toString(compilerWarnings));
Expand All @@ -90,17 +90,17 @@ protected Map<String, Object> getOptions() {

private String getDependencyClasspath() {
return StringUtils.join(getDependencies("jar").stream()
.map(Path::toFile)
.map(jar -> jar.getAbsolutePath())
.collect(Collectors.toList()), File.pathSeparatorChar);
.map(Path::toFile)
.map(File::getAbsolutePath)
.collect(Collectors.toList()), File.pathSeparatorChar);
}

private File getCompilerSettings() {
if (Files.exists(compilerSettings)) {
return compilerSettings.toFile();
} else if (compilerWarnings) {
getLog().warn("Could not locate compiler settings file: " + compilerSettings
+ " continuing with default compiler settings");
+ " continuing with default compiler settings");
}
return null;
}
Expand All @@ -109,4 +109,4 @@ protected final List<Path> getDependencies(String type) {
return MavenRuntime.getDependencies(project, type);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ private List<File> getDependencyIarJars() {
if (!Files.exists(iarJarClasspath)) {
return Collections.emptyList();
}
var iarJars = new ClasspathJar(iarJarClasspath).getFiles();
return iarJars;
return new ClasspathJar(iarJarClasspath).getFiles();
}
}
24 changes: 11 additions & 13 deletions src/main/java/ch/ivyteam/ivy/maven/deploy/AbstractDeployMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo {
*
* <pre>
* <code>deployTestUsers: auto
*target:
* version: RELEASED
* state: ACTIVE_AND_RELEASED</code>
* target:
* &nbsp;&nbsp;version: RELEASED
* &nbsp;&nbsp;state: ACTIVE_AND_RELEASED</code>
* </pre>
*
* <p>
Expand All @@ -168,9 +168,9 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo {
*
* <pre>
* <code>deployTestUsers: ${ivy.deploy.test.users}
*target:
* version: AUTO
* state: ${ivy.deploy.target.state}</code>
* target:
* &nbsp;&nbsp;version: AUTO
* &nbsp;&nbsp;state: ${ivy.deploy.target.state}</code>
* </pre>
*
* <p>
Expand Down Expand Up @@ -211,9 +211,7 @@ public abstract class AbstractDeployMojo extends AbstractIntegrationTestMojo {
@Parameter(property = "ivy.deploy.engine.app")
String deployToEngineApplication;

public AbstractDeployMojo() {
super();
}
public AbstractDeployMojo() {}

protected final boolean checkSkip() {
if (skipDeploy) {
Expand All @@ -228,7 +226,7 @@ protected final boolean checkSkip() {
}

protected final Path createDeployOptionsFile(DeploymentOptionsFileFactory optionsFileFactory)
throws MojoExecutionException {
throws MojoExecutionException {
if (deployOptionsFile != null) {
return optionsFileFactory.createFromTemplate(deployOptionsFile, project, session, fileFilter);
}
Expand All @@ -255,7 +253,7 @@ protected static void deleteFile(Path file) {
}

protected final void deployToDirectory(Path resolvedOptionsFile, Path deployDir)
throws MojoExecutionException {
throws MojoExecutionException {
var targetDeployableFile = createTargetDeployableFile(deployDir);
String deployablePath = deployDir.relativize(targetDeployableFile).toString();
IvyDeployer deployer = new FileDeployer(deployDir, resolvedOptionsFile, deployTimeoutInSeconds, deployFile, targetDeployableFile);
Expand All @@ -264,7 +262,7 @@ protected final void deployToDirectory(Path resolvedOptionsFile, Path deployDir)

private final Path createTargetDeployableFile(Path deployDir) {
return deployDir
.resolve(deployToEngineApplication)
.resolve(deployFile.getFileName().toString());
.resolve(deployToEngineApplication)
.resolve(deployFile.getFileName().toString());
}
}
22 changes: 11 additions & 11 deletions src/main/java/ch/ivyteam/ivy/maven/deploy/DeployToEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
if (StringUtils.isEmpty(deployToEngineApplication)) {
throw new MojoExecutionException(
"The parameter 'deployToEngineApplication' for goal " + GOAL + " is missing.");
"The parameter 'deployToEngineApplication' for goal " + GOAL + " is missing.");
}

var resolvedOptionsFile = createDeployOptionsFile(new DeploymentOptionsFileFactory(deployFile));
Expand All @@ -154,22 +154,22 @@ private void deployWithOptions(Path resolvedOptionsFile) throws MojoExecutionExc
deployToRestService(resolvedOptionsFile);
} else {
getLog().warn("Invalid deploy method " + deployMethod
+ " configured in parameter deployMethod (Supported values are " + DeployMethod.DIRECTORY + ", "
+ DeployMethod.HTTP + ")");
+ " configured in parameter deployMethod (Supported values are " + DeployMethod.DIRECTORY + ", "
+ DeployMethod.HTTP + ")");
}
}

private void deployToDirectory(Path resolvedOptionsFile) throws MojoExecutionException {
var deployDir = getDeployDirectory();
if (deployEngineDirectory == null) {
getLog().warn("Skipping deployment, target engine could not be evaluated." +
"Please configure an existing engine to deploy to with argument <deployEngineDirectory>.");
"Please configure an existing engine to deploy to with argument <deployEngineDirectory>.");
return;
}

if (!Files.exists(deployDir)) {
getLog().warn("Skipping deployment to engine '" + deployEngineDirectory + "'. The directory '"
+ deployDir + "' does not exist.");
+ deployDir + "' does not exist.");
return;
}
checkDirParams();
Expand All @@ -182,7 +182,7 @@ private void deployToRestService(Path resolvedOptionsFile) throws MojoExecutionE
Server server = session.getSettings().getServer(deployServerId);
if (server == null) {
getLog().warn("Can not load credentials from settings.xml because server '" + deployServerId
+ "' is not definied. Try to deploy with default username, password");
+ "' is not definied. Try to deploy with default username, password");
}
var httpDeployer = new HttpDeployer(secDispatcher, server, deployEngineUrl, deployToEngineApplication, deployFile, resolvedOptionsFile);
httpDeployer.deploy(getLog());
Expand All @@ -194,9 +194,9 @@ private void checkHttpParams() {
}
Object defaultDeployEngineDirectory = project.getProperties().get(ENGINE_DIRECTORY_PROPERTY);
if (deployEngineDirectory != null
&& !deployEngineDirectory.toFile().getPath().equals(defaultDeployEngineDirectory)) {
&& !deployEngineDirectory.toFile().getPath().equals(defaultDeployEngineDirectory)) {
logParameterIgnoredByMethod("deployEngineDirectory", deployEngineDirectory.toFile().getPath(),
DeployMethod.HTTP);
DeployMethod.HTTP);
}
}

Expand All @@ -211,7 +211,7 @@ private void checkDirParams() {

private void logParameterIgnoredByMethod(String parameter, String value, String method) {
getLog().warn("Parameter " + parameter + " is set to " + value + " but will be ignored by " + method
+ " deployment.");
+ " deployment.");
}

private Path getDeployDirectory() throws MojoExecutionException {
Expand All @@ -224,14 +224,14 @@ private Path getDeployDirectory() throws MojoExecutionException {
return deployEngineDirectory.resolve(deployDirectory);
}

public static interface DefaultDeployOptions {
public interface DefaultDeployOptions {
String VERSION_AUTO = "AUTO";
String STATE_ACTIVE_AND_RELEASED = "ACTIVE_AND_RELEASED";
String FILE_FORMAT_AUTO = "AUTO";
String DEPLOY_TEST_USERS = "AUTO";
}

public static interface DeployMethod {
public interface DeployMethod {
String DIRECTORY = "DIRECTORY";
String HTTP = "HTTP";
}
Expand Down
Loading

0 comments on commit ad7ab60

Please sign in to comment.