Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify usage of Optional instances #407

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions japicmp-ant-task/src/main/java/japicmp/ant/JApiCmpTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import japicmp.output.xml.XmlOutput;
import japicmp.output.xml.XmlOutputGenerator;
import japicmp.output.xml.XmlOutputGeneratorOptions;
import japicmp.util.Optional;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
Expand All @@ -29,6 +28,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static japicmp.model.AccessModifier.toModifier;
import static japicmp.util.FileHelper.createFileList;
Expand Down Expand Up @@ -242,18 +242,18 @@ private Options createOptionsFromAntAttrs() {
Options options = Options.newDefault();
options.getOldArchives().addAll(createFileList(this.oldJar));
options.getNewArchives().addAll(createFileList(this.newJar));
options.setXmlOutputFile(Optional.fromNullable(xmlOutputFile));
options.setHtmlOutputFile(Optional.fromNullable(htmlOutputFile));
options.setHtmlStylesheet(Optional.fromNullable(htmlStylesheet));
options.setXmlOutputFile(Optional.ofNullable(xmlOutputFile));
options.setHtmlOutputFile(Optional.ofNullable(htmlOutputFile));
options.setHtmlStylesheet(Optional.ofNullable(htmlStylesheet));
options.setOutputOnlyModifications(onlyModified);
options.setAccessModifier(toModifier(accessModifier));
options.addIncludeFromArgument(Optional.fromNullable(includes), includeExclusively);
options.addExcludeFromArgument(Optional.fromNullable(excludes), excludeExclusively);
options.addIncludeFromArgument(Optional.ofNullable(includes), includeExclusively);
options.addExcludeFromArgument(Optional.ofNullable(excludes), excludeExclusively);
options.setOutputOnlyBinaryIncompatibleModifications(onlyBinaryIncompatible);
options.setIncludeSynthetic(includeSynthetic);
options.setIgnoreMissingClasses(ignoreMissingClasses);
options.setOldClassPath(Optional.fromNullable(getOldClassPath().size() > 0 ? getOldClassPath().toString() : null));
options.setNewClassPath(Optional.fromNullable(getNewClassPath().size() > 0 ? getNewClassPath().toString() : null));
options.setOldClassPath(Optional.ofNullable(getOldClassPath().size() > 0 ? getOldClassPath().toString() : null));
options.setNewClassPath(Optional.ofNullable(getNewClassPath().size() > 0 ? getNewClassPath().toString() : null));
options.setNoAnnotations(noAnnotations);
for (String missingClassRegEx : ignoreMissingClassesByRegularExpressions) {
options.addIgnoreMissingClassRegularExpression(missingClassRegEx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import japicmp.output.xml.XmlOutput;
import japicmp.output.xml.XmlOutputGenerator;
import japicmp.output.xml.XmlOutputGeneratorOptions;
import japicmp.util.Optional;
import japicmp.versioning.SemanticVersion;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -118,22 +117,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {
this.mavenProject, this.mojoExecution, this.versionRangeWithProjectVersion, this.repoSystem, this.repoSession,
this.remoteRepos);
PluginParameters pluginParameters = new PluginParameters(this.skipExec || this.skip, this.newVersion, this.oldVersion, this.parameter, this.dependencies, Optional.of(
this.projectBuildDir), Optional.<String>absent(), true, this.oldVersions, this.newVersions, this.oldClassPathDependencies,
this.projectBuildDir), Optional.<String>empty(), true, this.oldVersions, this.newVersions, this.oldClassPathDependencies,
this.newClassPathDependencies);
executeWithParameters(pluginParameters, mavenParameters);
}

Optional<HtmlOutput> executeWithParameters(PluginParameters pluginParameters, MavenParameters mavenParameters) throws MojoFailureException, MojoExecutionException {
if (pluginParameters.getSkipParam()) {
getLog().info("Skipping execution because parameter 'skip' was set to true.");
return Optional.absent();
return Optional.empty();
}
if (isPomModuleNeedingSkip(pluginParameters, mavenParameters)) {
getLog().info("Skipping execution because parameter 'skipPomModules' was set to true and this is artifact is of type pom.");
return Optional.absent();
return Optional.empty();
}
if (skipModule(pluginParameters, mavenParameters)) {
return Optional.absent();
return Optional.empty();
}
Options options = getOptions(pluginParameters, mavenParameters);
JarArchiveComparatorOptions comparatorOptions = JarArchiveComparatorOptions.of(options);
Expand All @@ -142,7 +141,7 @@ Optional<HtmlOutput> executeWithParameters(PluginParameters pluginParameters, Ma
JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(comparatorOptions);
if (options.getNewArchives().isEmpty()) {
getLog().warn("Skipping execution because no new version could be resolved/found.");
return Optional.absent();
return Optional.empty();
}
List<JApiClass> jApiClasses = jarArchiveComparator.compare(options.getOldArchives(), options.getNewArchives());
try {
Expand All @@ -164,7 +163,7 @@ Optional<HtmlOutput> executeWithParameters(PluginParameters pluginParameters, Ma
}
}
}
Optional<HtmlOutput> retVal = Optional.absent();
Optional<HtmlOutput> retVal = Optional.empty();
if (!skipHtmlReport(pluginParameters)) {
HtmlOutput htmlOutput = generateHtmlOutput(jApiClasses, jApiCmpBuildDir, options, mavenParameters, pluginParameters, semanticVersioningInformation);
retVal = Optional.of(htmlOutput);
Expand Down Expand Up @@ -470,13 +469,13 @@ Options getOptions(PluginParameters pluginParameters, MavenParameters mavenParam
List<String> excludes = parameterParam.getExcludes();
if (excludes != null) {
for (String exclude : excludes) {
this.options.addExcludeFromArgument(Optional.fromNullable(exclude), parameterParam.isExcludeExclusively());
this.options.addExcludeFromArgument(Optional.ofNullable(exclude), parameterParam.isExcludeExclusively());
}
}
List<String> includes = parameterParam.getIncludes();
if (includes != null) {
for (String include : includes) {
this.options.addIncludeFromArgument(Optional.fromNullable(include), parameterParam.isIncludeExlusively());
this.options.addIncludeFromArgument(Optional.ofNullable(include), parameterParam.isIncludeExlusively());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import japicmp.config.Options;
import japicmp.output.html.HtmlOutput;
import japicmp.util.Optional;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.plugin.MojoExecution;
Expand All @@ -20,6 +19,7 @@
import java.io.File;
import java.util.List;
import java.util.Locale;
import java.util.Optional;

@Mojo(name = "cmp-report", defaultPhase = LifecyclePhase.SITE)
public class JApiCmpReport extends AbstractMavenReport {
Expand Down Expand Up @@ -121,7 +121,7 @@ private JApiCmpMojo getMojo() {
this.mavenParameters = new MavenParameters(this.artifactRepositories,
this.mavenProject, this.mojoExecution, this.versionRangeWithProjectVersion, this.repoSystem, this.repoSession,
this.remoteRepos);
this.pluginParameters = new PluginParameters(this.skip, this.newVersion, this.oldVersion, this.parameter, this.dependencies, Optional.<File>absent(), Optional.of(
this.pluginParameters = new PluginParameters(this.skip, this.newVersion, this.oldVersion, this.parameter, this.dependencies, Optional.<File>empty(), Optional.of(
this.outputDirectory), false, this.oldVersions, this.newVersions, this.oldClassPathDependencies, this.newClassPathDependencies);
return this.mojo;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package japicmp.maven;

import japicmp.util.Optional;

import java.io.File;
import java.util.List;
import java.util.Optional;

public class PluginParameters {
private final boolean skipParam;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import japicmp.maven.util.CtFieldBuilder;
import japicmp.maven.util.CtInterfaceBuilder;
import japicmp.maven.util.CtMethodBuilder;
import japicmp.util.Optional;
import javassist.ClassPool;
import javassist.CtClass;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -19,6 +18,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringContains.containsString;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.maven;

import japicmp.util.Optional;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.logging.Log;
Expand All @@ -13,6 +12,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Optional;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
Expand Down Expand Up @@ -101,7 +101,7 @@ private PluginParameters createPluginParameters() {
Version newVersion = JApiCmpMojoTest.createVersion("groupId", "artifactId", "0.1.1");
Parameter parameter = new Parameter();
return new PluginParameters(false, newVersion, oldVersion, parameter, new ArrayList<Dependency>(),
Optional.<File>absent(), Optional.<String>absent(), false, new ArrayList<DependencyDescriptor>(),
Optional.<File>empty(), Optional.<String>empty(), false, new ArrayList<DependencyDescriptor>(),
new ArrayList<DependencyDescriptor>(), new ArrayList<Dependency>(), new ArrayList<Dependency>());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.maven.util;

import com.google.common.base.Optional;
import japicmp.util.ModifierHelper;
import javassist.ClassPool;
import javassist.CtClass;
Expand All @@ -12,13 +11,14 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class CtClassBuilder {
private static final String DEFAULT_CLASS_NAME = "japicmp.Test";
private String name = DEFAULT_CLASS_NAME;
private int modifier = Modifier.PUBLIC;
private final List<String> annotations = new ArrayList<>();
private Optional<CtClass> superclass = Optional.absent();
private Optional<CtClass> superclass = Optional.empty();
private final List<CtClass> interfaces = new ArrayList<>();

public CtClassBuilder name(String name) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package japicmp.maven.util;

import com.google.common.base.Optional;
import javassist.CannotCompileException;
import javassist.ClassPool;
import javassist.CtClass;

import java.util.Optional;

public class CtInterfaceBuilder {
private String name = "japicmp.Test";
private Optional<CtClass> superInterfaceOptional = Optional.absent();
private Optional<CtClass> superInterfaceOptional = Optional.empty();

public CtInterfaceBuilder name(String name) {
this.name = name;
Expand All @@ -29,7 +30,7 @@ public static CtInterfaceBuilder create() {
}

public CtInterfaceBuilder withSuperInterface(CtClass superInterface) {
this.superInterfaceOptional = Optional.fromNullable(superInterface);
this.superInterfaceOptional = Optional.ofNullable(superInterface);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test.service;

import com.google.common.base.Optional;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -9,6 +8,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Optional;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
Expand All @@ -30,6 +30,6 @@ private Optional<String> findLineThatContains(List<String> lines, String str) {
return Optional.of(line);
}
}
return Optional.absent();
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import japicmp.model.JApiClass;
import japicmp.model.JApiField;
import japicmp.model.JApiSuperclass;
import japicmp.util.Optional;
import org.junit.BeforeClass;
import org.junit.Test;

import java.util.List;
import java.util.Optional;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import japicmp.output.xml.XmlOutput;
import japicmp.output.xml.XmlOutputGenerator;
import japicmp.output.xml.XmlOutputGeneratorOptions;
import japicmp.util.Optional;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
Expand All @@ -25,6 +24,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class Helper {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test;

import japicmp.util.Optional;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.model.JApiChangeStatus;
Expand All @@ -9,6 +8,7 @@
import org.junit.Test;

import java.util.List;
import java.util.Optional;

import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test;

import japicmp.util.Optional;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.model.AccessModifier;
Expand All @@ -11,6 +10,7 @@
import org.junit.Test;

import java.util.List;
import java.util.Optional;

import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test;

import japicmp.util.Optional;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.model.AccessModifier;
Expand Down Expand Up @@ -29,6 +28,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test;

import japicmp.util.Optional;
import japicmp.cmp.JApiCmpArchive;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
Expand All @@ -21,6 +20,7 @@
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test;

import japicmp.util.Optional;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.model.JApiChangeStatus;
Expand All @@ -9,6 +8,7 @@
import org.junit.Test;

import java.util.List;
import java.util.Optional;

import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package japicmp.test;

import japicmp.util.Optional;
import japicmp.cmp.JApiCmpArchive;
import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
Expand All @@ -24,6 +23,7 @@
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.List;
import java.util.Optional;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
Expand Down Expand Up @@ -53,10 +53,10 @@ public void test() throws IOException, CannotCompileException, NotFoundException
assertThat(syntheticClass.getSyntheticAttribute().getNewAttribute(), is(Optional.of(SyntheticAttribute.SYNTHETIC)));
assertThat(getJApiMethod(syntheticClass.getMethods(), "newMethod").getChangeStatus(), is(JApiChangeStatus.NEW));
assertThat(getJApiMethod(syntheticClass.getMethods(), "newMethod").getSyntheticAttribute().getChangeStatus(), is(JApiChangeStatus.NEW));
assertThat(getJApiMethod(syntheticClass.getMethods(), "newMethod").getSyntheticAttribute().getOldAttribute(), is(Optional.<SyntheticAttribute>absent()));
assertThat(getJApiMethod(syntheticClass.getMethods(), "newMethod").getSyntheticAttribute().getOldAttribute(), is(Optional.<SyntheticAttribute>empty()));
assertThat(getJApiMethod(syntheticClass.getMethods(), "newMethod").getSyntheticAttribute().getNewAttribute(), is(Optional.of(SyntheticAttribute.SYNTHETIC)));
assertThat(getJApiField(syntheticClass.getFields(), "newField").getSyntheticAttribute().getChangeStatus(), is(JApiChangeStatus.NEW));
assertThat(getJApiField(syntheticClass.getFields(), "newField").getSyntheticAttribute().getOldAttribute(), is(Optional.<SyntheticAttribute>absent()));
assertThat(getJApiField(syntheticClass.getFields(), "newField").getSyntheticAttribute().getOldAttribute(), is(Optional.<SyntheticAttribute>empty()));
assertThat(getJApiField(syntheticClass.getFields(), "newField").getSyntheticAttribute().getNewAttribute(), is(Optional.of(SyntheticAttribute.SYNTHETIC)));
}

Expand Down
Loading
Loading