Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Dec 13, 2023
1 parent c8d4ae6 commit ca78dc7
Show file tree
Hide file tree
Showing 89 changed files with 4,416 additions and 4,229 deletions.
949 changes: 475 additions & 474 deletions pom.xml

Large diffs are not rendered by default.

81 changes: 42 additions & 39 deletions src/main/java/org/codehaus/mojo/jaxb2/AbstractJaxbMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@
* under the License.
*/

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
Expand All @@ -38,23 +55,6 @@
import org.codehaus.mojo.jaxb2.shared.version.DependsFileParser;
import org.sonatype.plexus.build.incremental.BuildContext;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;

/**
* Abstract Mojo which collects common infrastructure, required and needed
* by all subclass Mojos in the JAXB2 maven plugin codebase.
Expand Down Expand Up @@ -117,18 +117,17 @@ public abstract class AbstractJaxbMojo extends AbstractMojo {
*/
public static final List<Filter<File>> STANDARD_EXCLUDE_FILTERS;

private static final List<String> RELEVANT_GROUPIDS =
Arrays.asList("com.sun.xml.bind", "jakarta.xml.bind");
private static final List<String> RELEVANT_GROUPIDS = Arrays.asList("com.sun.xml.bind", "jakarta.xml.bind");
private static final String OWN_ARTIFACT_ID = "jaxb2-maven-plugin";
private static final String SYSTEM_FILE_ENCODING_PROPERTY = "file.encoding";
private static final String[] STANDARD_EXCLUDE_SUFFIXES = {"README.*", "\\.xml", "\\.txt"};
private static final String[] STANDARD_PRELOADED_CLASSES = {
"com.sun.tools.xjc.addon.episode.package-info",
"com.sun.tools.xjc.reader.xmlschema.bindinfo.package-info",
"org.glassfish.jaxb.core.v2.model.core.package-info",
"org.glassfish.jaxb.runtime.v2.model.runtime.package-info",
"org.glassfish.jaxb.core.v2.schemagen.episode.package-info",
"org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.package-info"
"com.sun.tools.xjc.addon.episode.package-info",
"com.sun.tools.xjc.reader.xmlschema.bindinfo.package-info",
"org.glassfish.jaxb.core.v2.model.core.package-info",
"org.glassfish.jaxb.runtime.v2.model.runtime.package-info",
"org.glassfish.jaxb.core.v2.schemagen.episode.package-info",
"org.glassfish.jaxb.runtime.v2.schemagen.xmlschema.package-info"
};

static {
Expand All @@ -148,9 +147,7 @@ public boolean accept(final File aFileOrDir) {
final String name = aFileOrDir.getName();

// Ignore hidden files and CVS directories
return name.startsWith(".")
|| (aFileOrDir.isDirectory() && name.equals("CVS"));

return name.startsWith(".") || (aFileOrDir.isDirectory() && name.equals("CVS"));
}
}));

Expand All @@ -163,7 +160,7 @@ public boolean accept(final File aFileOrDir) {

final ClassLoader cl = AbstractJaxbMojo.class.getClassLoader();

for(String current : STANDARD_PRELOADED_CLASSES) {
for (String current : STANDARD_PRELOADED_CLASSES) {
cl.loadClass(current);
}

Expand Down Expand Up @@ -452,7 +449,12 @@ protected final String[] logAndReturnToolArguments(final String[] arguments, fin
argBuilder.append("\n+=================== [" + arguments.length + " " + toolName + " Arguments]\n");
argBuilder.append("|\n");
for (int i = 0; i < arguments.length; i++) {
argBuilder.append("| [").append(i).append("]: ").append(arguments[i]).append("\n");
argBuilder
.append("| [")
.append(i)
.append("]: ")
.append(arguments[i])
.append("\n");
}
argBuilder.append("|\n");
argBuilder.append("+=================== [End " + arguments.length + " " + toolName + " Arguments]\n\n");
Expand Down Expand Up @@ -510,8 +512,8 @@ protected final String getEncoding(final boolean warnIfPlatformEncoding) {
if (!configuredEncoding && warnIfPlatformEncoding) {
getLog().warn("Using platform encoding [" + effectiveEncoding + "], i.e. build is platform dependent!");
} else if (getLog().isDebugEnabled()) {
getLog().debug("Using " + (configuredEncoding ? "explicitly configured" : "system property")
+ " encoding [" + effectiveEncoding + "]");
getLog().debug("Using " + (configuredEncoding ? "explicitly configured" : "system property") + " encoding ["
+ effectiveEncoding + "]");
}

// All Done.
Expand Down Expand Up @@ -552,8 +554,8 @@ protected File getEpisodeFile(final String episodeFileName) throws MojoExecution
generatedJaxbEpisodeDirectory = episodePath.toFile();

if (getLog().isInfoEnabled()) {
getLog().info("Created EpisodePath [" + episodePath.toString() + "]: " +
(generatedJaxbEpisodeDirectory.exists() && generatedJaxbEpisodeDirectory.isDirectory()));
getLog().info("Created EpisodePath [" + episodePath.toString() + "]: "
+ (generatedJaxbEpisodeDirectory.exists() && generatedJaxbEpisodeDirectory.isDirectory()));
}

} catch (IOException e) {
Expand All @@ -568,8 +570,8 @@ protected File getEpisodeFile(final String episodeFileName) throws MojoExecution
File episodeFile = new File(generatedJaxbEpisodeDirectory, effectiveEpisodeFileName + ".xjb");
final AtomicInteger index = new AtomicInteger(1);
while (episodeFile.exists()) {
episodeFile = new File(generatedJaxbEpisodeDirectory,
effectiveEpisodeFileName + "_" + index.getAndIncrement() + ".xjb");
episodeFile = new File(
generatedJaxbEpisodeDirectory, effectiveEpisodeFileName + "_" + index.getAndIncrement() + ".xjb");
}

// Add the (generated) outputDirectory to the Resources.
Expand Down Expand Up @@ -638,8 +640,8 @@ private void logPluginAndJaxbDependencyInfo() {
private <T> T getInjectedObject(final T objectOrNull, final String objectName) {

if (objectOrNull == null) {
getLog().error(
"Found null '" + objectName + "', implying that Maven @Component injection was not done properly.");
getLog().error("Found null '" + objectName
+ "', implying that Maven @Component injection was not done properly.");
}

return objectOrNull;
Expand Down Expand Up @@ -684,7 +686,8 @@ protected void logSystemPropertiesAndBasedir() {

// Sort the system properties
final SortedMap<String, Object> props = new TreeMap<String, Object>();
props.put("basedir", FileSystemUtilities.getCanonicalPath(getProject().getBasedir()));
props.put(
"basedir", FileSystemUtilities.getCanonicalPath(getProject().getBasedir()));

for (Map.Entry<Object, Object> current : System.getProperties().entrySet()) {
props.put("" + current.getKey(), current.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* under the License.
*/


/**
* @author <a href="mailto:Olivier.LAMY@accor.com">olamy</a>
* @version $Id$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
* under the License.
*/

import java.io.File;
import java.io.FileWriter;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.sun.tools.xjc.Driver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -39,16 +49,6 @@
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;

import java.io.File;
import java.io.FileWriter;
import java.net.HttpURLConnection;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* <p>Abstract superclass for Mojos generating Java source or binaries from XML schema(s) by invoking the JAXB XJC
* binding compiler. Most of the Configuration options for the AbstractJavaGeneratorMojo are set or copied to the
Expand All @@ -60,7 +60,8 @@
*/
public abstract class AbstractJavaGeneratorMojo extends AbstractJaxbMojo {

private static final List<String> PROXY_PROPERTY_KEYS = Arrays.asList("http.proxyHost", "http.proxyPort", "https.proxyHost", "https.proxyPort");
private static final List<String> PROXY_PROPERTY_KEYS =
Arrays.asList("http.proxyHost", "http.proxyPort", "https.proxyHost", "https.proxyPort");

private static final int XJC_COMPLETED_OK = 0;

Expand Down Expand Up @@ -443,7 +444,8 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE
final LocaleFacet localeFacet = locale == null ? null : LocaleFacet.createFor(locale, getLog());

// Create the ToolExecutionEnvironment
environment = new ToolExecutionEnvironment(getLog(),
environment = new ToolExecutionEnvironment(
getLog(),
ThreadContextClassLoaderBuilder.createFor(this.getClass(), getLog(), getEncoding(false))
.addPaths(getClasspath()),
LoggingHandlerEnvironmentFacet.create(getLog(), getClass(), getEncoding(false)),
Expand Down Expand Up @@ -501,7 +503,10 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE

final List<URL> sourceXSDs = getSources();
for (int i = 0; i < sourceXSDs.size(); i++) {
errorMsgBuilder.append("| " + i + ": ").append(sourceXSDs.get(i).toString()).append("\n");
errorMsgBuilder
.append("| " + i + ": ")
.append(sourceXSDs.get(i).toString())
.append("\n");
}

errorMsgBuilder.append("|\n");
Expand Down Expand Up @@ -543,8 +548,8 @@ protected boolean performExecution() throws MojoExecutionException, MojoFailureE
// jar:file:/path/to/aJar.jar!/some/path/xsd/aResource.xsd
final int bangIndex = current.toString().indexOf("!");
if (bangIndex == -1) {
throw new MojoExecutionException("Illegal JAR URL [" + current.toString()
+ "]: lacks a '!'");
throw new MojoExecutionException(
"Illegal JAR URL [" + current.toString() + "]: lacks a '!'");
}

final String internalPath = current.toString().substring(bangIndex + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
* under the License.
*/

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -32,13 +39,6 @@
import org.codehaus.mojo.jaxb2.shared.filters.Filters;
import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* <p>Mojo that creates test-scope Java source or binaries from XML schema(s)
* by invoking the JAXB XJC binding compiler. This implementation is tailored
Expand All @@ -51,7 +51,8 @@
* @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>
* @see <a href="https://jaxb.java.net/">The JAXB Reference Implementation</a>
*/
@Mojo(name = "testXjc",
@Mojo(
name = "testXjc",
defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES,
requiresDependencyResolution = ResolutionScope.TEST,
threadSafe = false)
Expand Down Expand Up @@ -112,7 +113,6 @@ public class TestXjcMojo extends AbstractJavaGeneratorMojo {
public static final List<Filter<File>> STANDARD_TEST_XJB_EXCLUDE_FILTERS;

static {

final List<Filter<File>> xjbTemp = new ArrayList<Filter<File>>();
xjbTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS);
xjbTemp.add(new PatternFileFilter(Arrays.asList("\\.xsd"), true));
Expand Down Expand Up @@ -261,9 +261,8 @@ protected boolean shouldExecutionBeSkipped() {
@Override
protected List<URL> getSources() {

final List<Filter<File>> excludePatterns = testSourceExcludeFilters == null
? STANDARD_TEST_SOURCE_EXCLUDE_FILTERS
: testSourceExcludeFilters;
final List<Filter<File>> excludePatterns =
testSourceExcludeFilters == null ? STANDARD_TEST_SOURCE_EXCLUDE_FILTERS : testSourceExcludeFilters;
Filters.initialize(getLog(), excludePatterns);

// All done.
Expand All @@ -282,9 +281,8 @@ protected List<URL> getSources() {
@Override
protected List<File> getSourceXJBs() {

final List<Filter<File>> excludePatterns = testXjbExcludeFilters == null
? STANDARD_TEST_XJB_EXCLUDE_FILTERS
: testXjbExcludeFilters;
final List<Filter<File>> excludePatterns =
testXjbExcludeFilters == null ? STANDARD_TEST_XJB_EXCLUDE_FILTERS : testXjbExcludeFilters;
Filters.initialize(getLog(), excludePatterns);

return FileSystemUtilities.filterFiles(
Expand Down
35 changes: 14 additions & 21 deletions src/main/java/org/codehaus/mojo/jaxb2/javageneration/XjcMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
* under the License.
*/

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -32,13 +39,6 @@
import org.codehaus.mojo.jaxb2.shared.filters.Filters;
import org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* <p>Mojo that creates compile-scope Java source or binaries from XML schema(s)
* by invoking the JAXB XJC binding compiler. This implementation is tailored
Expand All @@ -51,7 +51,8 @@
* @author <a href="mailto:lj@jguru.se">Lennart J&ouml;relid</a>
* @see <a href="https://jaxb.java.net/">The JAXB Reference Implementation</a>
*/
@Mojo(name = "xjc",
@Mojo(
name = "xjc",
threadSafe = true,
defaultPhase = LifecyclePhase.GENERATE_SOURCES,
requiresDependencyResolution = ResolutionScope.COMPILE)
Expand Down Expand Up @@ -109,7 +110,6 @@ public class XjcMojo extends AbstractJavaGeneratorMojo {
public static final List<Filter<File>> STANDARD_XJB_EXCLUDE_FILTERS;

static {

final List<Filter<File>> xjbTemp = new ArrayList<Filter<File>>();
xjbTemp.addAll(AbstractJaxbMojo.STANDARD_EXCLUDE_FILTERS);
xjbTemp.add(new PatternFileFilter(Arrays.asList("\\.xsd"), true));
Expand Down Expand Up @@ -273,9 +273,8 @@ protected boolean shouldExecutionBeSkipped() {
@Override
protected List<URL> getSources() {

final List<Filter<File>> excludePatterns = xjcSourceExcludeFilters == null
? STANDARD_SOURCE_EXCLUDE_FILTERS
: xjcSourceExcludeFilters;
final List<Filter<File>> excludePatterns =
xjcSourceExcludeFilters == null ? STANDARD_SOURCE_EXCLUDE_FILTERS : xjcSourceExcludeFilters;
Filters.initialize(getLog(), excludePatterns);

return FileSystemUtilities.filterFiles(
Expand All @@ -293,18 +292,12 @@ protected List<URL> getSources() {
@Override
protected List<File> getSourceXJBs() {

final List<Filter<File>> excludePatterns = xjbExcludeFilters == null
? STANDARD_XJB_EXCLUDE_FILTERS
: xjbExcludeFilters;
final List<Filter<File>> excludePatterns =
xjbExcludeFilters == null ? STANDARD_XJB_EXCLUDE_FILTERS : xjbExcludeFilters;
Filters.initialize(getLog(), excludePatterns);

return FileSystemUtilities.filterFiles(
getProject().getBasedir(),
xjbSources,
STANDARD_XJB_DIRECTORY,
getLog(),
"xjbSources",
excludePatterns);
getProject().getBasedir(), xjbSources, STANDARD_XJB_DIRECTORY, getLog(), "xjbSources", excludePatterns);
}

/**
Expand Down
Loading

0 comments on commit ca78dc7

Please sign in to comment.