You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2023/04/08 15:58:36 UTC
[maven-shared-jar] 02/02: [MSHARED-1226] Upgrade Parent to 39 - code reformat
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MSHARED-1226
in repository https://gitbox.apache.org/repos/asf/maven-shared-jar.git
commit beea3fa1a1e844aa3b564cbd4d5dbef32cd27d74
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Sat Apr 8 17:57:02 2023 +0200
[MSHARED-1226] Upgrade Parent to 39 - code reformat
---
pom.xml | 9 +-
.../org/apache/maven/shared/jar/JarAnalyzer.java | 95 +++++-------
.../java/org/apache/maven/shared/jar/JarData.java | 80 ++++------
.../maven/shared/jar/classes/ImportVisitor.java | 106 +++++--------
.../maven/shared/jar/classes/JarClasses.java | 73 ++++-----
.../shared/jar/classes/JarClassesAnalysis.java | 134 ++++++----------
.../jar/identification/JarIdentification.java | 127 ++++++----------
.../identification/JarIdentificationAnalysis.java | 84 ++++-------
.../identification/JarIdentificationExposer.java | 8 +-
.../exposers/EmbeddedMavenModelExposer.java | 87 +++++------
.../identification/exposers/FilenameExposer.java | 44 +++---
.../identification/exposers/JarClassesExposer.java | 24 ++-
.../identification/exposers/ManifestExposer.java | 45 +++---
.../exposers/RepositorySearchExposer.java | 55 +++----
.../exposers/StaticMainOutputExposer.java | 26 ++--
.../identification/exposers/TextFileExposer.java | 62 +++-----
.../identification/exposers/TimestampExposer.java | 46 +++---
.../hash/JarBytecodeHashAnalyzer.java | 46 +++---
.../identification/hash/JarFileHashAnalyzer.java | 32 ++--
.../jar/identification/hash/JarHashAnalyzer.java | 8 +-
.../repository/EmptyRepositoryHashSearch.java | 15 +-
.../repository/RepositoryHashSearch.java | 10 +-
.../shared/jar/AbstractJarAnalyzerTestCase.java | 60 ++++----
.../apache/maven/shared/jar/JarAnalyzerTest.java | 92 ++++-------
.../shared/jar/classes/ImportVisitorTest.java | 60 ++++----
.../shared/jar/classes/JarClassesAnalyzerTest.java | 168 ++++++++-------------
.../JarIdentificationAnalyzerTest.java | 73 ++++-----
.../exposers/EmbeddedMavenModelExposerTest.java | 62 ++++----
28 files changed, 679 insertions(+), 1052 deletions(-)
diff --git a/pom.xml b/pom.xml
index 1b4feaa..79a20c8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
@@ -17,7 +17,6 @@
~ specific language governing permissions and limitations
~ under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -32,15 +31,13 @@
<version>2.0-SNAPSHOT</version>
<name>Apache Maven JAR Utilities</name>
- <description>
- Utilities that help identify the contents of a JAR, including Java class analysis and Maven metadata analysis.
- </description>
+ <description>Utilities that help identify the contents of a JAR, including Java class analysis and Maven metadata analysis.</description>
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-shared-jar.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-shared-jar.git</developerConnection>
- <url>https://github.com/apache/maven-shared-jar/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/maven-shared-jar/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>jira</system>
diff --git a/src/main/java/org/apache/maven/shared/jar/JarAnalyzer.java b/src/main/java/org/apache/maven/shared/jar/JarAnalyzer.java
index 21fd7b9..6c9a92c 100644
--- a/src/main/java/org/apache/maven/shared/jar/JarAnalyzer.java
+++ b/src/main/java/org/apache/maven/shared/jar/JarAnalyzer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar;
import java.io.File;
import java.io.IOException;
@@ -62,24 +61,23 @@ import java.util.zip.ZipException;
* @see org.apache.maven.shared.jar.identification.JarIdentificationAnalysis#analyze(JarAnalyzer)
* @see org.apache.maven.shared.jar.classes.JarClassesAnalysis#analyze(JarAnalyzer)
*/
-public class JarAnalyzer
-{
+public class JarAnalyzer {
/**
* Pattern to filter JAR entries for class files.
*
* @todo why are inner classes and other potentially valid classes omitted? (It flukes it by finding everything after $)
*/
- private static final Pattern CLASS_FILTER = Pattern.compile( "[A-Za-z0-9]*\\.class$" );
+ private static final Pattern CLASS_FILTER = Pattern.compile("[A-Za-z0-9]*\\.class$");
/**
* Pattern to filter JAR entries for Maven POM files.
*/
- private static final Pattern MAVEN_POM_FILTER = Pattern.compile( "META-INF/maven/.*/pom\\.xml$" );
+ private static final Pattern MAVEN_POM_FILTER = Pattern.compile("META-INF/maven/.*/pom\\.xml$");
/**
* Pattern to filter JAR entries for text files that may contain a version.
*/
- private static final Pattern VERSION_FILTER = Pattern.compile( "[Vv][Ee][Rr][Ss][Ii][Oo][Nn]" );
+ private static final Pattern VERSION_FILTER = Pattern.compile("[Vv][Ee][Rr][Ss][Ii][Oo][Nn]");
/**
* The associated JAR file.
@@ -98,37 +96,29 @@ public class JarAnalyzer
* @throws java.io.IOException if there is a problem opening the JAR file, or reading the manifest. The JAR file
* will be closed if this occurs.
*/
- public JarAnalyzer( File file )
- throws IOException
- {
- try
- {
- this.jarFile = new JarFile( file );
- }
- catch ( ZipException e )
- {
- ZipException ioe = new ZipException( "Failed to open file " + file + " : " + e.getMessage() );
- ioe.initCause( e );
+ public JarAnalyzer(File file) throws IOException {
+ try {
+ this.jarFile = new JarFile(file);
+ } catch (ZipException e) {
+ ZipException ioe = new ZipException("Failed to open file " + file + " : " + e.getMessage());
+ ioe.initCause(e);
throw ioe;
}
// Obtain entries list.
- List<JarEntry> entries = Collections.list( jarFile.entries() );
+ List<JarEntry> entries = Collections.list(jarFile.entries());
// Sorting of list is done by name to ensure a bytecode hash is always consistent.
- entries.sort( Comparator.comparing( ZipEntry::getName ) );
+ entries.sort(Comparator.comparing(ZipEntry::getName));
Manifest manifest;
- try
- {
+ try {
manifest = jarFile.getManifest();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
closeQuietly();
throw e;
}
- this.jarData = new JarData( file, manifest, entries );
+ this.jarData = new JarData(file, manifest, entries);
}
/**
@@ -139,23 +129,17 @@ public class JarAnalyzer
* @return the input stream of the individual JAR entry.
* @throws java.io.IOException if there is a problem opening the individual entry
*/
- public InputStream getEntryInputStream( JarEntry entry )
- throws IOException
- {
- return jarFile.getInputStream( entry );
+ public InputStream getEntryInputStream(JarEntry entry) throws IOException {
+ return jarFile.getInputStream(entry);
}
/**
* Close the associated JAR file, ignoring any errors that may occur.
*/
- public void closeQuietly()
- {
- try
- {
+ public void closeQuietly() {
+ try {
jarFile.close();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
// not much we can do about it but ignore it
}
}
@@ -166,16 +150,13 @@ public class JarAnalyzer
* @param pattern the pattern to filter against
* @return the list of files found, in {@link java.util.jar.JarEntry} elements
*/
- public List<JarEntry> filterEntries( Pattern pattern )
- {
+ public List<JarEntry> filterEntries(Pattern pattern) {
List<JarEntry> ret = new ArrayList<>();
- for ( JarEntry entry : getEntries() )
- {
- Matcher mat = pattern.matcher( entry.getName() );
- if ( mat.find() )
- {
- ret.add( entry );
+ for (JarEntry entry : getEntries()) {
+ Matcher mat = pattern.matcher(entry.getName());
+ if (mat.find()) {
+ ret.add(entry);
}
}
return ret;
@@ -186,9 +167,8 @@ public class JarAnalyzer
*
* @return the list of files found, in {@link java.util.jar.JarEntry} elements
*/
- public List<JarEntry> getClassEntries()
- {
- return filterEntries( CLASS_FILTER );
+ public List<JarEntry> getClassEntries() {
+ return filterEntries(CLASS_FILTER);
}
/**
@@ -196,9 +176,8 @@ public class JarAnalyzer
*
* @return the list of files found, in {@link java.util.jar.JarEntry} elements
*/
- public List<JarEntry> getMavenPomEntries()
- {
- return filterEntries( MAVEN_POM_FILTER );
+ public List<JarEntry> getMavenPomEntries() {
+ return filterEntries(MAVEN_POM_FILTER);
}
/**
@@ -206,9 +185,8 @@ public class JarAnalyzer
*
* @return the list of files found, in {@link java.util.jar.JarEntry} elements
*/
- public List<JarEntry> getVersionEntries()
- {
- return filterEntries( VERSION_FILTER );
+ public List<JarEntry> getVersionEntries() {
+ return filterEntries(VERSION_FILTER);
}
/**
@@ -216,8 +194,7 @@ public class JarAnalyzer
*
* @return the list of files found, in {@link java.util.jar.JarEntry} elements
*/
- public List<JarEntry> getEntries()
- {
+ public List<JarEntry> getEntries() {
return jarData.getEntries();
}
@@ -226,13 +203,11 @@ public class JarAnalyzer
*
* @return the JAR file reference
*/
- public File getFile()
- {
+ public File getFile() {
return jarData.getFile();
}
- public JarData getJarData()
- {
+ public JarData getJarData() {
return jarData;
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/JarData.java b/src/main/java/org/apache/maven/shared/jar/JarData.java
index 6c8739a..e9a85e4 100644
--- a/src/main/java/org/apache/maven/shared/jar/JarData.java
+++ b/src/main/java/org/apache/maven/shared/jar/JarData.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,10 +16,7 @@ package org.apache.maven.shared.jar;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.jar.classes.JarClasses;
-import org.apache.maven.shared.jar.identification.JarIdentification;
-import org.codehaus.plexus.util.StringUtils;
+package org.apache.maven.shared.jar;
import java.io.File;
import java.util.Collections;
@@ -30,11 +25,14 @@ import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.Manifest;
+import org.apache.maven.shared.jar.classes.JarClasses;
+import org.apache.maven.shared.jar.identification.JarIdentification;
+import org.codehaus.plexus.util.StringUtils;
+
/**
* Class that contains details of a single JAR file and it's entries.
*/
-public final class JarData
-{
+public final class JarData {
/**
* The JAR file.
*/
@@ -82,108 +80,88 @@ public final class JarData
* @param manifest the JAR manifest
* @param entries the JAR entries
*/
- public JarData( File file, Manifest manifest, List<JarEntry> entries )
- {
+ public JarData(File file, Manifest manifest, List<JarEntry> entries) {
this.file = file;
this.manifest = manifest;
- this.entries = Collections.unmodifiableList( entries );
+ this.entries = Collections.unmodifiableList(entries);
boolean sealed = false;
- if ( this.manifest != null )
- {
- String sval = this.manifest.getMainAttributes().getValue( Attributes.Name.SEALED );
- if ( StringUtils.isNotEmpty( sval ) )
- {
- sealed = "true".equalsIgnoreCase( sval.trim() );
+ if (this.manifest != null) {
+ String sval = this.manifest.getMainAttributes().getValue(Attributes.Name.SEALED);
+ if (StringUtils.isNotEmpty(sval)) {
+ sealed = "true".equalsIgnoreCase(sval.trim());
}
}
this.sealed = sealed;
}
- public List<JarEntry> getEntries()
- {
+ public List<JarEntry> getEntries() {
return entries;
}
- public Manifest getManifest()
- {
+ public Manifest getManifest() {
return manifest;
}
- public File getFile()
- {
+ public File getFile() {
return file;
}
- public boolean isSealed()
- {
+ public boolean isSealed() {
return sealed;
}
- public void setFileHash( String fileHash )
- {
+ public void setFileHash(String fileHash) {
this.fileHash = fileHash;
}
- public String getFileHash()
- {
+ public String getFileHash() {
return fileHash;
}
- public void setBytecodeHash( String bytecodeHash )
- {
+ public void setBytecodeHash(String bytecodeHash) {
this.bytecodeHash = bytecodeHash;
}
- public String getBytecodeHash()
- {
+ public String getBytecodeHash() {
return bytecodeHash;
}
- public boolean isDebugPresent()
- {
+ public boolean isDebugPresent() {
return jarClasses.isDebugPresent();
}
- public void setJarClasses( JarClasses jarClasses )
- {
+ public void setJarClasses(JarClasses jarClasses) {
this.jarClasses = jarClasses;
}
- public int getNumEntries()
- {
+ public int getNumEntries() {
return entries.size();
}
- public int getNumClasses()
- {
+ public int getNumClasses() {
return jarClasses.getClassNames().size();
}
- public int getNumPackages()
- {
+ public int getNumPackages() {
return jarClasses.getPackages().size();
}
- public String getJdkRevision()
- {
+ public String getJdkRevision() {
return jarClasses.getJdkRevision();
}
- public void setJarIdentification( JarIdentification jarIdentification )
- {
+ public void setJarIdentification(JarIdentification jarIdentification) {
this.jarIdentification = jarIdentification;
}
- public JarIdentification getJarIdentification()
- {
+ public JarIdentification getJarIdentification() {
return jarIdentification;
}
- public JarClasses getJarClasses()
- {
+ public JarClasses getJarClasses() {
return jarClasses;
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java b/src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java
index e5a5e69..7485b04 100644
--- a/src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java
+++ b/src/main/java/org/apache/maven/shared/jar/classes/ImportVisitor.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.classes;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,12 @@ package org.apache.maven.shared.jar.classes;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.classes;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantUtf8;
@@ -25,17 +29,10 @@ import org.apache.bcel.classfile.EmptyVisitor;
import org.apache.bcel.classfile.JavaClass;
import org.apache.commons.collections4.list.SetUniqueList;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
/**
* Implementation of a BCEL class visitor that analyzes a class and collects imports.
*/
-public class ImportVisitor
- extends EmptyVisitor
-{
+public class ImportVisitor extends EmptyVisitor {
/**
* The list of imports discovered.
*/
@@ -50,25 +47,24 @@ public class ImportVisitor
* Pattern to detect if the import is qualified and allows retrieval of the actual import name from the string via
* the group 1.
*/
- private static final Pattern QUALIFIED_IMPORT_PATTERN = Pattern.compile( "L([a-zA-Z][a-zA-Z0-9\\.]+);" );
+ private static final Pattern QUALIFIED_IMPORT_PATTERN = Pattern.compile("L([a-zA-Z][a-zA-Z0-9\\.]+);");
/**
* Pattern that checks whether a string is valid UTF-8. Imports that are not are ignored.
*/
- private static final Pattern VALID_UTF8_PATTERN = Pattern.compile( "^[\\(\\)\\[A-Za-z0-9;/]+$" );
+ private static final Pattern VALID_UTF8_PATTERN = Pattern.compile("^[\\(\\)\\[A-Za-z0-9;/]+$");
/**
* Create an Import visitor.
*
* @param javaClass the javaclass to work from
*/
- public ImportVisitor( JavaClass javaClass )
- {
+ public ImportVisitor(JavaClass javaClass) {
this.javaClass = javaClass;
// Create a list that is guaranteed to be unique while retaining it's list qualities (LinkedHashSet does not
- // expose the list interface even if natural ordering is retained)
- this.imports = SetUniqueList.setUniqueList( new ArrayList<>() );
+ // expose the list interface even if natural ordering is retained)
+ this.imports = SetUniqueList.setUniqueList(new ArrayList<>());
}
/**
@@ -76,8 +72,7 @@ public class ImportVisitor
*
* @return Returns the imports.
*/
- public List<String> getImports()
- {
+ public List<String> getImports() {
return imports;
}
@@ -87,31 +82,25 @@ public class ImportVisitor
* @see org.apache.bcel.classfile.EmptyVisitor#visitConstantClass(org.apache.bcel.classfile.ConstantClass)
*/
@Override
- public void visitConstantClass( ConstantClass constantClass )
- {
- String name = constantClass.getBytes( javaClass.getConstantPool() );
+ public void visitConstantClass(ConstantClass constantClass) {
+ String name = constantClass.getBytes(javaClass.getConstantPool());
// only strings with '/' character are to be considered.
- if ( name.indexOf( '/' ) == -1 )
- {
+ if (name.indexOf('/') == -1) {
return;
}
- name = name.replace( '/', '.' );
+ name = name.replace('/', '.');
- if ( name.endsWith( ".class" ) )
- {
- name = name.substring( 0, name.length() - 6 );
+ if (name.endsWith(".class")) {
+ name = name.substring(0, name.length() - 6);
}
- Matcher mat = QUALIFIED_IMPORT_PATTERN.matcher( name );
- if ( mat.find() )
- {
- this.imports.add( mat.group( 1 ) );
- }
- else
- {
- this.imports.add( name );
+ Matcher mat = QUALIFIED_IMPORT_PATTERN.matcher(name);
+ if (mat.find()) {
+ this.imports.add(mat.group(1));
+ } else {
+ this.imports.add(name);
}
}
@@ -121,70 +110,57 @@ public class ImportVisitor
* @see org.apache.bcel.classfile.EmptyVisitor#visitConstantUtf8(org.apache.bcel.classfile.ConstantUtf8)
*/
@Override
- public void visitConstantUtf8( ConstantUtf8 constantUtf8 )
- {
+ public void visitConstantUtf8(ConstantUtf8 constantUtf8) {
String ret = constantUtf8.getBytes().trim();
// empty strings are not class names.
- if ( ret.length() <= 0 )
- {
+ if (ret.length() <= 0) {
return;
}
// Only valid characters please.
- if ( !VALID_UTF8_PATTERN.matcher( ret ).matches() )
- {
+ if (!VALID_UTF8_PATTERN.matcher(ret).matches()) {
return;
}
// only strings with '/' character are to be considered.
- if ( ret.indexOf( '/' ) == -1 )
- {
+ if (ret.indexOf('/') == -1) {
return;
}
// Strings that start with '/' are bad too
// Seen when Pool has regex patterns.
- if ( ret.charAt( 0 ) == '/' )
- {
+ if (ret.charAt(0) == '/') {
return;
}
// Make string more class-like.
- ret = ret.replace( '/', '.' );
+ ret = ret.replace('/', '.');
// Double ".." indicates a bad class fail-fast.
// Seen when ConstantUTF8 Pool has regex patterns.
- if ( ret.contains( ".." ) )
- {
+ if (ret.contains("..")) {
return;
}
- Matcher mat = QUALIFIED_IMPORT_PATTERN.matcher( ret );
- char prefix = ret.charAt( 0 );
+ Matcher mat = QUALIFIED_IMPORT_PATTERN.matcher(ret);
+ char prefix = ret.charAt(0);
- if ( prefix == '(' )
- {
+ if (prefix == '(') {
// A Method Declaration.
// Loop for each Qualified Class found.
- while ( mat.find() )
- {
- this.imports.add( mat.group( 1 ) );
+ while (mat.find()) {
+ this.imports.add(mat.group(1));
}
- }
- else
- {
+ } else {
// A Variable Declaration.
- if ( mat.find() )
- {
+ if (mat.find()) {
// Add a UTF8 Qualified Class reference.
- this.imports.add( mat.group( 1 ) );
- }
- else
- {
+ this.imports.add(mat.group(1));
+ } else {
// Add a simple Class reference.
- this.imports.add( ret );
+ this.imports.add(ret);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/classes/JarClasses.java b/src/main/java/org/apache/maven/shared/jar/classes/JarClasses.java
index 6f5f30e..92f31de 100644
--- a/src/main/java/org/apache/maven/shared/jar/classes/JarClasses.java
+++ b/src/main/java/org/apache/maven/shared/jar/classes/JarClasses.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.classes;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,20 +16,20 @@ package org.apache.maven.shared.jar.classes;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.commons.collections4.list.SetUniqueList;
+package org.apache.maven.shared.jar.classes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import org.apache.commons.collections4.list.SetUniqueList;
+
/**
* Gathered facts about the classes within a JAR file.
*
* @see org.apache.maven.shared.jar.classes.JarClassesAnalysis#analyze(org.apache.maven.shared.jar.JarAnalyzer)
*/
-public class JarClasses
-{
+public class JarClasses {
/**
* The list of imports in the classes in the JAR.
*/
@@ -67,14 +65,13 @@ public class JarClasses
/**
* Constructor to create an empty instance.
*/
- public JarClasses()
- {
+ public JarClasses() {
// Unique list decorators are used to ensure natural ordering is retained, the list interface is availble, and
// that duplicates are not entered.
- imports = SetUniqueList.setUniqueList( new ArrayList<>() );
- packages = SetUniqueList.setUniqueList( new ArrayList<>() );
- classNames = SetUniqueList.setUniqueList( new ArrayList<>() );
- methods = SetUniqueList.setUniqueList( new ArrayList<>() );
+ imports = SetUniqueList.setUniqueList(new ArrayList<>());
+ packages = SetUniqueList.setUniqueList(new ArrayList<>());
+ classNames = SetUniqueList.setUniqueList(new ArrayList<>());
+ methods = SetUniqueList.setUniqueList(new ArrayList<>());
}
/**
@@ -82,9 +79,8 @@ public class JarClasses
*
* @param name the name of the class
*/
- public void addClassName( String name )
- {
- this.classNames.add( name );
+ public void addClassName(String name) {
+ this.classNames.add(name);
}
/**
@@ -92,9 +88,8 @@ public class JarClasses
*
* @param name the name of the package
*/
- public void addPackage( String name )
- {
- this.packages.add( name );
+ public void addPackage(String name) {
+ this.packages.add(name);
}
/**
@@ -102,9 +97,8 @@ public class JarClasses
*
* @param name the name of the method
*/
- public void addMethod( String name )
- {
- this.methods.add( name );
+ public void addMethod(String name) {
+ this.methods.add(name);
}
/**
@@ -112,48 +106,39 @@ public class JarClasses
*
* @param imports the imports to add. Each item should be a String to avoid down the line ClassCastExceptions.
*/
- public void addImports( List<String> imports )
- {
- this.imports.addAll( imports );
+ public void addImports(List<String> imports) {
+ this.imports.addAll(imports);
}
- public List<String> getImports()
- {
- return Collections.unmodifiableList( imports );
+ public List<String> getImports() {
+ return Collections.unmodifiableList(imports);
}
- public List<String> getClassNames()
- {
- return Collections.unmodifiableList( classNames );
+ public List<String> getClassNames() {
+ return Collections.unmodifiableList(classNames);
}
- public List<String> getPackages()
- {
- return Collections.unmodifiableList( packages );
+ public List<String> getPackages() {
+ return Collections.unmodifiableList(packages);
}
- public boolean isDebugPresent()
- {
+ public boolean isDebugPresent() {
return isDebugPresent;
}
- public void setDebugPresent( boolean hasDebugSymbols )
- {
+ public void setDebugPresent(boolean hasDebugSymbols) {
this.isDebugPresent = hasDebugSymbols;
}
- public String getJdkRevision()
- {
+ public String getJdkRevision() {
return jdkRevision;
}
- public void setJdkRevision( String jdkRevision )
- {
+ public void setJdkRevision(String jdkRevision) {
this.jdkRevision = jdkRevision;
}
- public List<String> getMethods()
- {
- return Collections.unmodifiableList( methods );
+ public List<String> getMethods() {
+ return Collections.unmodifiableList(methods);
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/classes/JarClassesAnalysis.java b/src/main/java/org/apache/maven/shared/jar/classes/JarClassesAnalysis.java
index 781de2f..ed78dd5 100644
--- a/src/main/java/org/apache/maven/shared/jar/classes/JarClassesAnalysis.java
+++ b/src/main/java/org/apache/maven/shared/jar/classes/JarClassesAnalysis.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.classes;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,10 +16,15 @@ package org.apache.maven.shared.jar.classes;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.classes;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.io.IOException;
+import java.util.List;
+import java.util.jar.JarEntry;
+
import org.apache.bcel.classfile.ClassFormatException;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.DescendingVisitor;
@@ -32,10 +35,6 @@ import org.apache.maven.shared.jar.JarAnalyzer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.util.List;
-import java.util.jar.JarEntry;
-
/**
* Analyze the classes in a JAR file. This class is thread safe and immutable as it retains no state.
*
@@ -46,9 +45,8 @@ import java.util.jar.JarEntry;
*/
@Singleton
@Named
-public class JarClassesAnalysis
-{
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+public class JarClassesAnalysis {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
private static final double JAVA_1_8_CLASS_VERSION = 52.0;
@@ -74,126 +72,94 @@ public class JarClassesAnalysis
* @param jarAnalyzer the JAR to analyze. This must not yet have been closed.
* @return the details of the classes found
*/
- public JarClasses analyze( JarAnalyzer jarAnalyzer )
- {
+ public JarClasses analyze(JarAnalyzer jarAnalyzer) {
JarClasses classes = jarAnalyzer.getJarData().getJarClasses();
- if ( classes == null )
- {
+ if (classes == null) {
String jarfilename = jarAnalyzer.getFile().getAbsolutePath();
classes = new JarClasses();
List<JarEntry> classList = jarAnalyzer.getClassEntries();
- classes.setDebugPresent( false );
+ classes.setDebugPresent(false);
double maxVersion = 0.0;
- for ( JarEntry entry : classList )
- {
+ for (JarEntry entry : classList) {
String classname = entry.getName();
- try
- {
- ClassParser classParser = new ClassParser( jarfilename, classname );
+ try {
+ ClassParser classParser = new ClassParser(jarfilename, classname);
JavaClass javaClass = classParser.parse();
String classSignature = javaClass.getClassName();
- if ( !classes.isDebugPresent() )
- {
- if ( hasDebugSymbols( javaClass ) )
- {
- classes.setDebugPresent( true );
+ if (!classes.isDebugPresent()) {
+ if (hasDebugSymbols(javaClass)) {
+ classes.setDebugPresent(true);
}
}
double classVersion = javaClass.getMajor();
- if ( javaClass.getMinor() > 0 )
- {
+ if (javaClass.getMinor() > 0) {
classVersion = classVersion + javaClass.getMinor() / 10.0;
}
- if ( classVersion > maxVersion )
- {
+ if (classVersion > maxVersion) {
maxVersion = classVersion;
}
Method[] methods = javaClass.getMethods();
- for ( Method method : methods )
- {
- classes.addMethod( classSignature + "." + method.getName() + method.getSignature() );
+ for (Method method : methods) {
+ classes.addMethod(classSignature + "." + method.getName() + method.getSignature());
}
String classPackageName = javaClass.getPackageName();
- classes.addClassName( classSignature );
- classes.addPackage( classPackageName );
+ classes.addClassName(classSignature);
+ classes.addPackage(classPackageName);
- ImportVisitor importVisitor = new ImportVisitor( javaClass );
- DescendingVisitor descVisitor = new DescendingVisitor( javaClass, importVisitor );
- javaClass.accept( descVisitor );
+ ImportVisitor importVisitor = new ImportVisitor(javaClass);
+ DescendingVisitor descVisitor = new DescendingVisitor(javaClass, importVisitor);
+ javaClass.accept(descVisitor);
- classes.addImports( importVisitor.getImports() );
- }
- catch ( ClassFormatException e )
- {
- logger.warn( "Unable to process class " + classname + " in JarAnalyzer File " + jarfilename,
- e );
- }
- catch ( IOException e )
- {
- logger.warn( "Unable to process JarAnalyzer File " + jarfilename, e );
+ classes.addImports(importVisitor.getImports());
+ } catch (ClassFormatException e) {
+ logger.warn("Unable to process class " + classname + " in JarAnalyzer File " + jarfilename, e);
+ } catch (IOException e) {
+ logger.warn("Unable to process JarAnalyzer File " + jarfilename, e);
}
}
- if ( maxVersion == JAVA_1_8_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.8" );
- }
- else if ( maxVersion == JAVA_1_7_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.7" );
- }
- else if ( maxVersion == JAVA_1_6_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.6" );
- }
- else if ( maxVersion == JAVA_1_5_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.5" );
- }
- else if ( maxVersion == JAVA_1_4_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.4" );
- }
- else if ( maxVersion == JAVA_1_3_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.3" );
- }
- else if ( maxVersion == JAVA_1_2_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.2" );
- }
- else if ( maxVersion == JAVA_1_1_CLASS_VERSION )
- {
- classes.setJdkRevision( "1.1" );
+ if (maxVersion == JAVA_1_8_CLASS_VERSION) {
+ classes.setJdkRevision("1.8");
+ } else if (maxVersion == JAVA_1_7_CLASS_VERSION) {
+ classes.setJdkRevision("1.7");
+ } else if (maxVersion == JAVA_1_6_CLASS_VERSION) {
+ classes.setJdkRevision("1.6");
+ } else if (maxVersion == JAVA_1_5_CLASS_VERSION) {
+ classes.setJdkRevision("1.5");
+ } else if (maxVersion == JAVA_1_4_CLASS_VERSION) {
+ classes.setJdkRevision("1.4");
+ } else if (maxVersion == JAVA_1_3_CLASS_VERSION) {
+ classes.setJdkRevision("1.3");
+ } else if (maxVersion == JAVA_1_2_CLASS_VERSION) {
+ classes.setJdkRevision("1.2");
+ } else if (maxVersion == JAVA_1_1_CLASS_VERSION) {
+ classes.setJdkRevision("1.1");
}
- jarAnalyzer.getJarData().setJarClasses( classes );
+ jarAnalyzer.getJarData().setJarClasses(classes);
}
return classes;
}
- private boolean hasDebugSymbols( JavaClass javaClass )
- {
+ private boolean hasDebugSymbols(JavaClass javaClass) {
boolean ret = false;
Method[] methods = javaClass.getMethods();
- for ( Method method : methods )
- {
+ for (Method method : methods) {
LineNumberTable linenumbers = method.getLineNumberTable();
- if ( linenumbers != null && linenumbers.getLength() > 0 )
- {
+ if (linenumbers != null && linenumbers.getLength() > 0) {
ret = true;
break;
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/JarIdentification.java b/src/main/java/org/apache/maven/shared/jar/identification/JarIdentification.java
index 8378f71..5df8eaf 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/JarIdentification.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/JarIdentification.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar.identification;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification;
import java.util.ArrayList;
import java.util.List;
@@ -27,8 +26,7 @@ import java.util.List;
*
* @see org.apache.maven.shared.jar.identification.JarIdentificationAnalysis#analyze(org.apache.maven.shared.jar.JarAnalyzer)
*/
-public class JarIdentification
-{
+public class JarIdentification {
/**
* The group ID derived or guessed from the list of potentials of the JAR.
*/
@@ -84,14 +82,12 @@ public class JarIdentification
*
* @param groupId the group ID discovered
*/
- public void addAndSetGroupId( String groupId )
- {
- if ( groupId != null )
- {
+ public void addAndSetGroupId(String groupId) {
+ if (groupId != null) {
this.groupId = groupId;
}
- addGroupId( groupId );
+ addGroupId(groupId);
}
/**
@@ -99,9 +95,8 @@ public class JarIdentification
*
* @param groupId the group ID discovered
*/
- public void addGroupId( String groupId )
- {
- addUnique( potentialGroupIds, groupId );
+ public void addGroupId(String groupId) {
+ addUnique(potentialGroupIds, groupId);
}
/**
@@ -109,14 +104,12 @@ public class JarIdentification
*
* @param artifactId the artifact ID discovered
*/
- public void addAndSetArtifactId( String artifactId )
- {
- if ( artifactId != null )
- {
+ public void addAndSetArtifactId(String artifactId) {
+ if (artifactId != null) {
this.artifactId = artifactId;
}
- addArtifactId( artifactId );
+ addArtifactId(artifactId);
}
/**
@@ -124,9 +117,8 @@ public class JarIdentification
*
* @param artifactId the artifact ID discovered
*/
- public void addArtifactId( String artifactId )
- {
- addUnique( potentialArtifactIds, artifactId );
+ public void addArtifactId(String artifactId) {
+ addUnique(potentialArtifactIds, artifactId);
}
/**
@@ -134,14 +126,12 @@ public class JarIdentification
*
* @param version the version discovered
*/
- public void addAndSetVersion( String version )
- {
- if ( version != null )
- {
+ public void addAndSetVersion(String version) {
+ if (version != null) {
this.version = version;
}
- addVersion( version );
+ addVersion(version);
}
/**
@@ -149,9 +139,8 @@ public class JarIdentification
*
* @param version the version discovered
*/
- public void addVersion( String version )
- {
- addUnique( potentialVersions, version );
+ public void addVersion(String version) {
+ addUnique(potentialVersions, version);
}
/**
@@ -159,14 +148,12 @@ public class JarIdentification
*
* @param name the vendor name discovered
*/
- public void addAndSetVendor( String name )
- {
- if ( name != null )
- {
+ public void addAndSetVendor(String name) {
+ if (name != null) {
vendor = name;
}
- addVendor( name );
+ addVendor(name);
}
/**
@@ -174,9 +161,8 @@ public class JarIdentification
*
* @param name the vendor name discovered
*/
- public void addVendor( String name )
- {
- addUnique( potentialVendors, name );
+ public void addVendor(String name) {
+ addUnique(potentialVendors, name);
}
/**
@@ -184,14 +170,12 @@ public class JarIdentification
*
* @param name the artifact name discovered
*/
- public void addAndSetName( String name )
- {
- if ( name != null )
- {
+ public void addAndSetName(String name) {
+ if (name != null) {
this.name = name;
}
- addName( name );
+ addName(name);
}
/**
@@ -199,94 +183,75 @@ public class JarIdentification
*
* @param name the artifact name discovered
*/
- public void addName( String name )
- {
- addUnique( potentialNames, name );
+ public void addName(String name) {
+ addUnique(potentialNames, name);
}
- private static void addUnique( List<String> list, String value )
- {
- if ( value != null )
- {
- if ( !list.contains( value ) )
- {
- list.add( value );
+ private static void addUnique(List<String> list, String value) {
+ if (value != null) {
+ if (!list.contains(value)) {
+ list.add(value);
}
}
}
- public String getArtifactId()
- {
+ public String getArtifactId() {
return artifactId;
}
- public void setArtifactId( String artifactId )
- {
+ public void setArtifactId(String artifactId) {
this.artifactId = artifactId;
}
- public String getGroupId()
- {
+ public String getGroupId() {
return groupId;
}
- public void setGroupId( String groupId )
- {
+ public void setGroupId(String groupId) {
this.groupId = groupId;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public void setName( String name )
- {
+ public void setName(String name) {
this.name = name;
}
- public String getVendor()
- {
+ public String getVendor() {
return vendor;
}
- public void setVendor( String vendor )
- {
+ public void setVendor(String vendor) {
this.vendor = vendor;
}
- public String getVersion()
- {
+ public String getVersion() {
return version;
}
- public void setVersion( String version )
- {
+ public void setVersion(String version) {
this.version = version;
}
- public List<String> getPotentialVersions()
- {
+ public List<String> getPotentialVersions() {
return potentialVersions;
}
- public List<String> getPotentialNames()
- {
+ public List<String> getPotentialNames() {
return potentialNames;
}
- public List<String> getPotentialGroupIds()
- {
+ public List<String> getPotentialGroupIds() {
return potentialGroupIds;
}
- public List<String> getPotentialArtifactIds()
- {
+ public List<String> getPotentialArtifactIds() {
return potentialArtifactIds;
}
- public List<String> getPotentialVendors()
- {
+ public List<String> getPotentialVendors() {
return potentialVendors;
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalysis.java b/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalysis.java
index 5de0aa0..20cfca1 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalysis.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalysis.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,16 +16,17 @@ package org.apache.maven.shared.jar.identification;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.util.List;
+
import org.apache.maven.shared.jar.JarAnalyzer;
import org.codehaus.plexus.util.StringUtils;
-import java.util.List;
-
import static java.util.Objects.requireNonNull;
/**
@@ -41,17 +40,15 @@ import static java.util.Objects.requireNonNull;
*/
@Singleton
@Named
-public class JarIdentificationAnalysis
-{
+public class JarIdentificationAnalysis {
/**
* The Maven information exposers to use during identification.
*/
private final List<JarIdentificationExposer> exposers;
@Inject
- public JarIdentificationAnalysis( List<JarIdentificationExposer> exposers )
- {
- this.exposers = requireNonNull( exposers );
+ public JarIdentificationAnalysis(List<JarIdentificationExposer> exposers) {
+ this.exposers = requireNonNull(exposers);
}
/**
@@ -62,86 +59,69 @@ public class JarIdentificationAnalysis
* @param jarAnalyzer the JAR to analyze. This must not yet have been closed.
* @return the Maven metadata discovered
*/
- public JarIdentification analyze( JarAnalyzer jarAnalyzer )
- {
+ public JarIdentification analyze(JarAnalyzer jarAnalyzer) {
JarIdentification taxon = jarAnalyzer.getJarData().getJarIdentification();
- if ( taxon != null )
- {
+ if (taxon != null) {
return taxon;
}
taxon = new JarIdentification();
- for ( JarIdentificationExposer exposer : exposers )
- {
- exposer.expose( taxon, jarAnalyzer );
+ for (JarIdentificationExposer exposer : exposers) {
+ exposer.expose(taxon, jarAnalyzer);
}
- normalize( taxon );
+ normalize(taxon);
- jarAnalyzer.getJarData().setJarIdentification( taxon );
+ jarAnalyzer.getJarData().setJarIdentification(taxon);
return taxon;
}
- private void normalize( JarIdentification taxon )
- {
- if ( StringUtils.isEmpty( taxon.getGroupId() ) )
- {
- taxon.setGroupId( pickSmallest( taxon.getPotentialGroupIds() ) );
+ private void normalize(JarIdentification taxon) {
+ if (StringUtils.isEmpty(taxon.getGroupId())) {
+ taxon.setGroupId(pickSmallest(taxon.getPotentialGroupIds()));
}
- if ( StringUtils.isEmpty( taxon.getArtifactId() ) )
- {
- taxon.setArtifactId( pickLargest( taxon.getPotentialArtifactIds() ) );
+ if (StringUtils.isEmpty(taxon.getArtifactId())) {
+ taxon.setArtifactId(pickLargest(taxon.getPotentialArtifactIds()));
}
- if ( StringUtils.isEmpty( taxon.getVersion() ) )
- {
- taxon.setVersion( pickSmallest( taxon.getPotentialVersions() ) );
+ if (StringUtils.isEmpty(taxon.getVersion())) {
+ taxon.setVersion(pickSmallest(taxon.getPotentialVersions()));
}
- if ( StringUtils.isEmpty( taxon.getName() ) )
- {
- taxon.setName( pickLargest( taxon.getPotentialNames() ) );
+ if (StringUtils.isEmpty(taxon.getName())) {
+ taxon.setName(pickLargest(taxon.getPotentialNames()));
}
- if ( StringUtils.isEmpty( taxon.getVendor() ) )
- {
- taxon.setVendor( pickLargest( taxon.getPotentialVendors() ) );
+ if (StringUtils.isEmpty(taxon.getVendor())) {
+ taxon.setVendor(pickLargest(taxon.getPotentialVendors()));
}
}
- private String pickSmallest( List<String> list )
- {
+ private String pickSmallest(List<String> list) {
String smallest = null;
int size = Integer.MAX_VALUE;
- for ( String val : list )
- {
- if ( StringUtils.isNotEmpty( val ) )
- {
- if ( val.length() < size )
- {
+ for (String val : list) {
+ if (StringUtils.isNotEmpty(val)) {
+ if (val.length() < size) {
smallest = val;
size = val.length();
}
}
}
-
+
return smallest;
}
- private String pickLargest( List<String> list )
- {
+ private String pickLargest(List<String> list) {
String largest = null;
int size = Integer.MIN_VALUE;
- for ( String val : list )
- {
- if ( StringUtils.isNotEmpty( val ) )
- {
- if ( val.length() > size )
- {
+ for (String val : list) {
+ if (StringUtils.isNotEmpty(val)) {
+ if (val.length() > size) {
largest = val;
size = val.length();
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationExposer.java
index 8321a7f..48f82ac 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/JarIdentificationExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar.identification;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification;
import org.apache.maven.shared.jar.JarAnalyzer;
@@ -26,8 +25,7 @@ import org.apache.maven.shared.jar.JarAnalyzer;
*
* @see org.apache.maven.shared.jar.identification.JarIdentificationAnalysis
*/
-public interface JarIdentificationExposer
-{
+public interface JarIdentificationExposer {
/**
* Expose metadata during the identification process.
*
@@ -35,5 +33,5 @@ public interface JarIdentificationExposer
* @param jarAnalyzer the JAR to obtain the information from. Should be treated as read only, with the exception
* of caching the metadata if it would be identical when run over the same file again.
*/
- void expose( JarIdentification identification, JarAnalyzer jarAnalyzer );
+ void expose(JarIdentification identification, JarAnalyzer jarAnalyzer);
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java
index 5e8e084..2b26157 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,10 +16,17 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+import java.util.jar.JarEntry;
+
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -32,81 +37,59 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.List;
-import java.util.jar.JarEntry;
-
/**
* Exposer that examines a JAR file for any embedded Maven metadata for identification.
*/
@Singleton
-@Named( "embeddedMavenModel" )
-public class EmbeddedMavenModelExposer
- implements JarIdentificationExposer
-{
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+@Named("embeddedMavenModel")
+public class EmbeddedMavenModelExposer implements JarIdentificationExposer {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
List<JarEntry> entries = jarAnalyzer.getMavenPomEntries();
- if ( entries.isEmpty() )
- {
+ if (entries.isEmpty()) {
return;
}
- if ( entries.size() > 1 )
- {
- logger.warn(
- "More than one Maven model entry was found in the JAR, using only the first of: " + entries );
+ if (entries.size() > 1) {
+ logger.warn("More than one Maven model entry was found in the JAR, using only the first of: " + entries);
}
- JarEntry pom = entries.get( 0 );
+ JarEntry pom = entries.get(0);
MavenXpp3Reader pomreader = new MavenXpp3Reader();
- try ( InputStream is = jarAnalyzer.getEntryInputStream( pom );
- InputStreamReader isreader = new InputStreamReader( is ) )
- {
- Model model = pomreader.read( isreader );
+ try (InputStream is = jarAnalyzer.getEntryInputStream(pom);
+ InputStreamReader isreader = new InputStreamReader(is)) {
+ Model model = pomreader.read(isreader);
- if ( model.getParent() != null )
- {
+ if (model.getParent() != null) {
// use parent values only if project values not exists
- if ( model.getGroupId() == null )
- {
- identification.addAndSetGroupId( model.getParent().getGroupId() );
+ if (model.getGroupId() == null) {
+ identification.addAndSetGroupId(model.getParent().getGroupId());
}
- if ( model.getVersion() == null )
- {
- identification.addAndSetVersion( model.getParent().getVersion() );
+ if (model.getVersion() == null) {
+ identification.addAndSetVersion(model.getParent().getVersion());
}
}
- identification.addAndSetGroupId( model.getGroupId() );
- identification.addAndSetArtifactId( model.getArtifactId() );
- identification.addAndSetVersion( model.getVersion() );
- identification.addAndSetName( model.getName() );
+ identification.addAndSetGroupId(model.getGroupId());
+ identification.addAndSetArtifactId(model.getArtifactId());
+ identification.addAndSetVersion(model.getVersion());
+ identification.addAndSetName(model.getName());
// TODO: suboptimal - we are reproducing Maven's built in default
- if ( model.getName() == null )
- {
- identification.addAndSetName( model.getArtifactId() );
+ if (model.getName() == null) {
+ identification.addAndSetName(model.getArtifactId());
}
Organization org = model.getOrganization();
- if ( org != null )
- {
- identification.addAndSetVendor( org.getName() );
+ if (org != null) {
+ identification.addAndSetVendor(org.getName());
}
- }
- catch ( IOException e )
- {
- logger.error( "Unable to read model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e );
- }
- catch ( XmlPullParserException e )
- {
- logger.error( "Unable to parse model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e );
+ } catch (IOException e) {
+ logger.error("Unable to read model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e);
+ } catch (XmlPullParserException e) {
+ logger.error("Unable to parse model " + pom.getName() + " in " + jarAnalyzer.getFile() + ".", e);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/FilenameExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/FilenameExposer.java
index e996cde..ff2095f 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/FilenameExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/FilenameExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,46 +16,40 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.identification.JarIdentification;
import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
import org.codehaus.plexus.util.FileUtils;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-
/**
* Exposer that examines a JAR file to derive Maven metadata from the pattern of the JAR's filename.
* Will match the format <i>artifactId</i>-<i>version</i>.jar.
*/
@Singleton
-@Named( "filename" )
-public class FilenameExposer
- implements JarIdentificationExposer
-{
- private static final Pattern VERSION_PATTERN = Pattern.compile( "-\\d" );
+@Named("filename")
+public class FilenameExposer implements JarIdentificationExposer {
+ private static final Pattern VERSION_PATTERN = Pattern.compile("-\\d");
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
- String filename = FileUtils.removeExtension( jarAnalyzer.getFile().getName() );
- Matcher mat = VERSION_PATTERN.matcher( filename );
- if ( mat.find() )
- {
- String prefix = filename.substring( 0, mat.start() );
- identification.addArtifactId( prefix );
- identification.addName( prefix );
- identification.addVersion( filename.substring( mat.end() - 1 ) );
- }
- else
- {
- identification.addArtifactId( filename );
- identification.addName( filename );
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
+ String filename = FileUtils.removeExtension(jarAnalyzer.getFile().getName());
+ Matcher mat = VERSION_PATTERN.matcher(filename);
+ if (mat.find()) {
+ String prefix = filename.substring(0, mat.start());
+ identification.addArtifactId(prefix);
+ identification.addName(prefix);
+ identification.addVersion(filename.substring(mat.end() - 1));
+ } else {
+ identification.addArtifactId(filename);
+ identification.addName(filename);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/JarClassesExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/JarClassesExposer.java
index db2f3b9..40b2cee 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/JarClassesExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/JarClassesExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Inject;
import javax.inject.Named;
@@ -36,26 +35,21 @@ import static java.util.Objects.requireNonNull;
* potential group IDs from the class packages.
*/
@Singleton
-@Named( "jarClasses" )
-public class JarClassesExposer
- implements JarIdentificationExposer
-{
+@Named("jarClasses")
+public class JarClassesExposer implements JarIdentificationExposer {
private final JarClassesAnalysis analyzer;
@Inject
- public JarClassesExposer( JarClassesAnalysis analyzer )
- {
- this.analyzer = requireNonNull( analyzer );
+ public JarClassesExposer(JarClassesAnalysis analyzer) {
+ this.analyzer = requireNonNull(analyzer);
}
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
- JarClasses jarclasses = analyzer.analyze( jarAnalyzer );
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
+ JarClasses jarclasses = analyzer.analyze(jarAnalyzer);
- for ( String packagename : jarclasses.getPackages() )
- {
- identification.addGroupId( packagename );
+ for (String packagename : jarclasses.getPackages()) {
+ identification.addGroupId(packagename);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/ManifestExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/ManifestExposer.java
index e932e91..684e1b4 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/ManifestExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/ManifestExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,50 +16,45 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.identification.JarIdentification;
import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
-
/**
* Exposer that examines a JAR's manifest to derive Maven metadata.
*/
@Singleton
-@Named( "manifest" )
-public class ManifestExposer
- implements JarIdentificationExposer
-{
+@Named("manifest")
+public class ManifestExposer implements JarIdentificationExposer {
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
Manifest manifest = jarAnalyzer.getJarData().getManifest();
- if ( manifest != null )
- {
- addManifestAttributeValues( manifest.getMainAttributes(), identification );
+ if (manifest != null) {
+ addManifestAttributeValues(manifest.getMainAttributes(), identification);
- for ( Attributes attribs : manifest.getEntries().values() )
- {
- addManifestAttributeValues( attribs, identification );
+ for (Attributes attribs : manifest.getEntries().values()) {
+ addManifestAttributeValues(attribs, identification);
}
}
}
- private void addManifestAttributeValues( Attributes attribs, JarIdentification identification )
- {
- identification.addName( attribs.getValue( Attributes.Name.IMPLEMENTATION_TITLE ) );
- identification.addVersion( attribs.getValue( Attributes.Name.IMPLEMENTATION_VERSION ) );
- identification.addVendor( attribs.getValue( Attributes.Name.IMPLEMENTATION_VENDOR ) );
+ private void addManifestAttributeValues(Attributes attribs, JarIdentification identification) {
+ identification.addName(attribs.getValue(Attributes.Name.IMPLEMENTATION_TITLE));
+ identification.addVersion(attribs.getValue(Attributes.Name.IMPLEMENTATION_VERSION));
+ identification.addVendor(attribs.getValue(Attributes.Name.IMPLEMENTATION_VENDOR));
- identification.addName( attribs.getValue( Attributes.Name.SPECIFICATION_TITLE ) );
- identification.addVersion( attribs.getValue( Attributes.Name.SPECIFICATION_VERSION ) );
- identification.addVendor( attribs.getValue( Attributes.Name.SPECIFICATION_VENDOR ) );
+ identification.addName(attribs.getValue(Attributes.Name.SPECIFICATION_TITLE));
+ identification.addVersion(attribs.getValue(Attributes.Name.SPECIFICATION_VERSION));
+ identification.addVendor(attribs.getValue(Attributes.Name.SPECIFICATION_VENDOR));
- identification.addGroupId( attribs.getValue( Attributes.Name.EXTENSION_NAME ) );
+ identification.addGroupId(attribs.getValue(Attributes.Name.EXTENSION_NAME));
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/RepositorySearchExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/RepositorySearchExposer.java
index 015d128..73f665b 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/RepositorySearchExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/RepositorySearchExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,11 +16,15 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.identification.JarIdentification;
@@ -30,9 +32,6 @@ import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
import org.apache.maven.shared.jar.identification.hash.JarHashAnalyzer;
import org.apache.maven.shared.jar.identification.repository.RepositoryHashSearch;
-import java.util.ArrayList;
-import java.util.List;
-
import static java.util.Objects.requireNonNull;
/**
@@ -40,10 +39,8 @@ import static java.util.Objects.requireNonNull;
* identical files, and files with identical classes.
*/
@Singleton
-@Named( "repositorySearch" )
-public class RepositorySearchExposer
- implements JarIdentificationExposer
-{
+@Named("repositorySearch")
+public class RepositorySearchExposer implements JarIdentificationExposer {
/**
* The repository searcher to use.
*
@@ -62,38 +59,34 @@ public class RepositorySearchExposer
private final JarHashAnalyzer bytecodeHashAnalyzer;
@Inject
- public RepositorySearchExposer( RepositoryHashSearch repositoryHashSearch,
- @Named( "file" ) JarHashAnalyzer fileHashAnalyzer,
- @Named( "bytecode" ) JarHashAnalyzer bytecodeHashAnalyzer )
- {
- this.repositoryHashSearch = requireNonNull( repositoryHashSearch );
- this.fileHashAnalyzer = requireNonNull( fileHashAnalyzer );
- this.bytecodeHashAnalyzer = requireNonNull( bytecodeHashAnalyzer );
+ public RepositorySearchExposer(
+ RepositoryHashSearch repositoryHashSearch,
+ @Named("file") JarHashAnalyzer fileHashAnalyzer,
+ @Named("bytecode") JarHashAnalyzer bytecodeHashAnalyzer) {
+ this.repositoryHashSearch = requireNonNull(repositoryHashSearch);
+ this.fileHashAnalyzer = requireNonNull(fileHashAnalyzer);
+ this.bytecodeHashAnalyzer = requireNonNull(bytecodeHashAnalyzer);
}
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
List<Artifact> repohits = new ArrayList<>();
- String hash = fileHashAnalyzer.computeHash( jarAnalyzer );
- if ( hash != null )
- {
- repohits.addAll( repositoryHashSearch.searchFileHash( hash ) );
+ String hash = fileHashAnalyzer.computeHash(jarAnalyzer);
+ if (hash != null) {
+ repohits.addAll(repositoryHashSearch.searchFileHash(hash));
}
- String bytecodehash = bytecodeHashAnalyzer.computeHash( jarAnalyzer );
- if ( bytecodehash != null )
- {
- repohits.addAll( repositoryHashSearch.searchBytecodeHash( bytecodehash ) );
+ String bytecodehash = bytecodeHashAnalyzer.computeHash(jarAnalyzer);
+ if (bytecodehash != null) {
+ repohits.addAll(repositoryHashSearch.searchBytecodeHash(bytecodehash));
}
// Found hits in the repository.
- for ( Artifact artifact : repohits )
- {
- identification.addAndSetGroupId( artifact.getGroupId() );
- identification.addAndSetArtifactId( artifact.getArtifactId() );
- identification.addAndSetVersion( artifact.getVersion() );
+ for (Artifact artifact : repohits) {
+ identification.addAndSetGroupId(artifact.getGroupId());
+ identification.addAndSetArtifactId(artifact.getArtifactId());
+ identification.addAndSetVersion(artifact.getVersion());
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/StaticMainOutputExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/StaticMainOutputExposer.java
index 261c02f..569bd11 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/StaticMainOutputExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/StaticMainOutputExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,17 +16,18 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.util.Collections;
+import java.util.List;
+
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.identification.JarIdentification;
import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
-import java.util.Collections;
-import java.util.List;
-
/**
* Exposer that examines a a JAR for classes that have <code>Version</code> in the name and calls their
* <code>main</code> method if it exists to obtain the version.
@@ -36,22 +35,17 @@ import java.util.List;
* TODO not currently implemented
*/
@Singleton
-@Named( "staticMainOutput" )
-public class StaticMainOutputExposer
- implements JarIdentificationExposer
-{
+@Named("staticMainOutput")
+public class StaticMainOutputExposer implements JarIdentificationExposer {
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
List<String> staticMains = findStaticMainVersions();
- for ( String ver : staticMains )
- {
- identification.addVersion( ver );
+ for (String ver : staticMains) {
+ identification.addVersion(ver);
}
}
- private List<String> findStaticMainVersions()
- {
+ private List<String> findStaticMainVersions() {
// TODO: Execute the static main methods of classes with 'Version' in their name.
return Collections.emptyList();
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposer.java
index 404f1dc..996f983 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/TextFileExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,17 +16,11 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Named;
import javax.inject.Singleton;
-import org.apache.maven.shared.jar.JarAnalyzer;
-import org.apache.maven.shared.jar.identification.JarIdentification;
-import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
-import org.codehaus.plexus.util.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -37,56 +29,52 @@ import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
+import org.apache.maven.shared.jar.JarAnalyzer;
+import org.apache.maven.shared.jar.identification.JarIdentification;
+import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
+import org.codehaus.plexus.util.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Exposer that examines a a JAR for files that contain the text <code>version</code> (case-insensitive) and
* adds the contents as potential version(s).
*/
@Singleton
-@Named( "textFile" )
-public class TextFileExposer
- implements JarIdentificationExposer
-{
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+@Named("textFile")
+public class TextFileExposer implements JarIdentificationExposer {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
- List<String> textFiles = findTextFileVersions( jarAnalyzer );
- for ( String ver : textFiles )
- {
- identification.addVersion( ver );
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
+ List<String> textFiles = findTextFileVersions(jarAnalyzer);
+ for (String ver : textFiles) {
+ identification.addVersion(ver);
}
}
- private List<String> findTextFileVersions( JarAnalyzer jarAnalyzer )
- {
+ private List<String> findTextFileVersions(JarAnalyzer jarAnalyzer) {
List<String> textVersions = new ArrayList<>();
List<JarEntry> hits = jarAnalyzer.getVersionEntries();
- for ( JarEntry entry : hits )
- {
+ for (JarEntry entry : hits) {
// skip this entry if it's a class file.
- if ( !entry.getName().endsWith( ".class" ) ) //$NON-NLS-1$
+ if (!entry.getName().endsWith(".class")) // $NON-NLS-1$
{
- logger.debug( "Version Hit: " + entry.getName() );
- try ( InputStream is = jarAnalyzer.getEntryInputStream( entry ) )
- {
- BufferedReader br = new BufferedReader( new InputStreamReader( is ) );
+ logger.debug("Version Hit: " + entry.getName());
+ try (InputStream is = jarAnalyzer.getEntryInputStream(entry)) {
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
// TODO: check for key=value pair.
// TODO: maybe even for groupId entries.
- logger.debug( line );
- if ( StringUtils.isNotEmpty( line ) )
- {
- textVersions.add( line );
+ logger.debug(line);
+ if (StringUtils.isNotEmpty(line)) {
+ textVersions.add(line);
}
- }
- catch ( IOException e )
- {
- logger.warn( "Unable to read line from " + entry.getName(), e );
+ } catch (IOException e) {
+ logger.warn("Unable to read line from " + entry.getName(), e);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/exposers/TimestampExposer.java b/src/main/java/org/apache/maven/shared/jar/identification/exposers/TimestampExposer.java
index 250d035..202d160 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/exposers/TimestampExposer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/exposers/TimestampExposer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,10 +16,17 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Locale;
+import java.util.jar.JarEntry;
+
import org.apache.commons.collections4.Bag;
import org.apache.commons.collections4.bag.HashBag;
import org.apache.maven.shared.jar.JarAnalyzer;
@@ -29,48 +34,35 @@ import org.apache.maven.shared.jar.identification.JarIdentification;
import org.apache.maven.shared.jar.identification.JarIdentificationExposer;
import org.codehaus.plexus.util.StringUtils;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.jar.JarEntry;
-
/**
* Exposer that examines a a JAR and uses the most recent timestamp as a potential version.
*/
@Singleton
-@Named( "timestamp" )
-public class TimestampExposer
- implements JarIdentificationExposer
-{
+@Named("timestamp")
+public class TimestampExposer implements JarIdentificationExposer {
@Override
- public void expose( JarIdentification identification, JarAnalyzer jarAnalyzer )
- {
+ public void expose(JarIdentification identification, JarAnalyzer jarAnalyzer) {
List<JarEntry> entries = jarAnalyzer.getEntries();
- SimpleDateFormat tsformat = new SimpleDateFormat( "yyyyMMdd", Locale.US ); //$NON-NLS-1$
+ SimpleDateFormat tsformat = new SimpleDateFormat("yyyyMMdd", Locale.US); // $NON-NLS-1$
Bag<String> timestamps = new HashBag<>();
- for ( JarEntry entry : entries )
- {
+ for (JarEntry entry : entries) {
long time = entry.getTime();
- String timestamp = tsformat.format( new Date( time ) );
- timestamps.add( timestamp );
+ String timestamp = tsformat.format(new Date(time));
+ timestamps.add(timestamp);
}
String ts = "";
int tsmax = 0;
- for ( String timestamp : timestamps )
- {
- int count = timestamps.getCount( timestamp );
- if ( count > tsmax )
- {
+ for (String timestamp : timestamps) {
+ int count = timestamps.getCount(timestamp);
+ if (count > tsmax) {
ts = timestamp;
tsmax = count;
}
}
- if ( StringUtils.isNotEmpty( ts ) )
- {
- identification.addVersion( ts );
+ if (StringUtils.isNotEmpty(ts)) {
+ identification.addVersion(ts);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java b/src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java
index 7a1d862..fab08fd 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.hash;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,55 +16,47 @@ package org.apache.maven.shared.jar.identification.hash;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.hash;
import javax.inject.Named;
import javax.inject.Singleton;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.jar.JarEntry;
+
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.JarData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.jar.JarEntry;
-
/**
* Analyzer that calculates the hash code for the entire file. Can be used to detect an exact copy of the file's class
* data. Useful to see thru a recompile, recompression, or timestamp change.
*/
@Singleton
-@Named( "bytecode" )
-public class JarBytecodeHashAnalyzer
- implements JarHashAnalyzer
-{
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+@Named("bytecode")
+public class JarBytecodeHashAnalyzer implements JarHashAnalyzer {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
- public String computeHash( JarAnalyzer jarAnalyzer )
- {
+ public String computeHash(JarAnalyzer jarAnalyzer) {
JarData jarData = jarAnalyzer.getJarData();
String result = jarData.getBytecodeHash();
- if ( result == null )
- {
+ if (result == null) {
List<JarEntry> entries = jarAnalyzer.getClassEntries();
- try
- {
- for ( JarEntry entry : entries )
- {
- try ( InputStream is = jarAnalyzer.getEntryInputStream( entry ) )
- {
- result = DigestUtils.sha1Hex( is );
+ try {
+ for (JarEntry entry : entries) {
+ try (InputStream is = jarAnalyzer.getEntryInputStream(entry)) {
+ result = DigestUtils.sha1Hex(is);
}
}
- jarData.setBytecodeHash( result );
- }
- catch ( IOException e )
- {
- logger.warn( "Unable to calculate the hashcode.", e );
+ jarData.setBytecodeHash(result);
+ } catch (IOException e) {
+ logger.warn("Unable to calculate the hashcode.", e);
}
}
return result;
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzer.java b/src/main/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzer.java
index ca499d9..94ec0a8 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/hash/JarFileHashAnalyzer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.hash;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar.identification.hash;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.hash;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -36,30 +35,23 @@ import org.slf4j.LoggerFactory;
* Analyzer that calculates the hash code for the entire file. Can be used to detect an exact copy of the file.
*/
@Singleton
-@Named( "file" )
-public class JarFileHashAnalyzer
- implements JarHashAnalyzer
-{
- private final Logger logger = LoggerFactory.getLogger( getClass() );
+@Named("file")
+public class JarFileHashAnalyzer implements JarHashAnalyzer {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
@Override
- public String computeHash( JarAnalyzer jarAnalyzer )
- {
+ public String computeHash(JarAnalyzer jarAnalyzer) {
JarData jarData = jarAnalyzer.getJarData();
String result = jarData.getFileHash();
- if ( result == null )
- {
- try
- {
- try ( InputStream inputStream = Files.newInputStream( jarData.getFile().toPath() ) )
- {
- jarData.setFileHash( DigestUtils.sha1Hex( inputStream ) );
+ if (result == null) {
+ try {
+ try (InputStream inputStream =
+ Files.newInputStream(jarData.getFile().toPath())) {
+ jarData.setFileHash(DigestUtils.sha1Hex(inputStream));
}
- }
- catch ( IOException e )
- {
- logger.warn( "Unable to calculate the hashcode.", e );
+ } catch (IOException e) {
+ logger.warn("Unable to calculate the hashcode.", e);
}
}
return result;
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/hash/JarHashAnalyzer.java b/src/main/java/org/apache/maven/shared/jar/identification/hash/JarHashAnalyzer.java
index 44e3bcd..e31fddc 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/hash/JarHashAnalyzer.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/hash/JarHashAnalyzer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.hash;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,19 +16,19 @@ package org.apache.maven.shared.jar.identification.hash;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.hash;
import org.apache.maven.shared.jar.JarAnalyzer;
/**
* Classes that can calculate various hash signatures for a JAR file to later uniquely identify them.
*/
-public interface JarHashAnalyzer
-{
+public interface JarHashAnalyzer {
/**
* Compute the hash for the JAR. The hashcode will then be cached in the JAR data class for later use.
*
* @param jarAnalyzer the JAR analyzer to use to obtain the entries to hash
* @return the hash, or null if not able to be computed due to an exception.
*/
- String computeHash( JarAnalyzer jarAnalyzer );
+ String computeHash(JarAnalyzer jarAnalyzer);
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/repository/EmptyRepositoryHashSearch.java b/src/main/java/org/apache/maven/shared/jar/identification/repository/EmptyRepositoryHashSearch.java
index 9bcd13a..784dfd8 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/repository/EmptyRepositoryHashSearch.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/repository/EmptyRepositoryHashSearch.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.repository;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar.identification.repository;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.repository;
import javax.inject.Named;
import javax.inject.Singleton;
@@ -35,17 +34,13 @@ import org.apache.maven.artifact.Artifact;
* real repository.
*/
@Singleton
-@Named( "empty" )
-public class EmptyRepositoryHashSearch
- implements RepositoryHashSearch
-{
- public List<Artifact> searchBytecodeHash( String hash )
- {
+@Named("empty")
+public class EmptyRepositoryHashSearch implements RepositoryHashSearch {
+ public List<Artifact> searchBytecodeHash(String hash) {
return Collections.emptyList();
}
- public List<Artifact> searchFileHash( String hash )
- {
+ public List<Artifact> searchFileHash(String hash) {
return Collections.emptyList();
}
}
diff --git a/src/main/java/org/apache/maven/shared/jar/identification/repository/RepositoryHashSearch.java b/src/main/java/org/apache/maven/shared/jar/identification/repository/RepositoryHashSearch.java
index 659c12f..4f1694a 100644
--- a/src/main/java/org/apache/maven/shared/jar/identification/repository/RepositoryHashSearch.java
+++ b/src/main/java/org/apache/maven/shared/jar/identification/repository/RepositoryHashSearch.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.repository;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jar.identification.repository;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.repository;
import java.util.List;
@@ -26,15 +25,14 @@ import org.apache.maven.artifact.Artifact;
/**
* Interface for Repository Hash Searches.
*/
-public interface RepositoryHashSearch
-{
+public interface RepositoryHashSearch {
/**
* Search the repository for artifacts matching the given hash code when consider the entire contents of the file.
*
* @param hash the hash code to use
* @return a list of {@link org.apache.maven.artifact.Artifact} instances that matched
*/
- List<Artifact> searchFileHash( String hash );
+ List<Artifact> searchFileHash(String hash);
/**
* Search the repository for artifacts matching the given hash code when consider the bytecode of the classes in the
@@ -43,5 +41,5 @@ public interface RepositoryHashSearch
* @param hash the hash code to use
* @return a list of {@link org.apache.maven.artifact.Artifact} instances that matched
*/
- List<Artifact> searchBytecodeHash( String hash );
+ List<Artifact> searchBytecodeHash(String hash);
}
diff --git a/src/test/java/org/apache/maven/shared/jar/AbstractJarAnalyzerTestCase.java b/src/test/java/org/apache/maven/shared/jar/AbstractJarAnalyzerTestCase.java
index 8f86fe9..edb4827 100644
--- a/src/test/java/org/apache/maven/shared/jar/AbstractJarAnalyzerTestCase.java
+++ b/src/test/java/org/apache/maven/shared/jar/AbstractJarAnalyzerTestCase.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,11 +16,7 @@ package org.apache.maven.shared.jar;
* specific language governing permissions and limitations
* under the License.
*/
-
-import junit.framework.AssertionFailedError;
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.PlexusConstants;
-import org.codehaus.plexus.PlexusTestCase;
+package org.apache.maven.shared.jar;
import java.io.File;
import java.io.UnsupportedEncodingException;
@@ -33,50 +27,48 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import junit.framework.AssertionFailedError;
+import org.codehaus.plexus.ContainerConfiguration;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusTestCase;
+
import static java.nio.charset.StandardCharsets.UTF_8;
/**
* Abstract JarAnalyzer TestCase
*/
-public abstract class AbstractJarAnalyzerTestCase
- extends PlexusTestCase
-{
+public abstract class AbstractJarAnalyzerTestCase extends PlexusTestCase {
@Override
- protected void customizeContainerConfiguration( ContainerConfiguration configuration )
- {
- configuration.setAutoWiring( true ).setClassPathScanning( PlexusConstants.SCANNING_CACHE );
+ protected void customizeContainerConfiguration(ContainerConfiguration configuration) {
+ configuration.setAutoWiring(true).setClassPathScanning(PlexusConstants.SCANNING_CACHE);
}
- protected File getSampleJar( String filename )
- throws UnsupportedEncodingException
- {
- String path = getClass().getResource( "/jars/" + filename ).getPath();
+ protected File getSampleJar(String filename) throws UnsupportedEncodingException {
+ String path = getClass().getResource("/jars/" + filename).getPath();
// URLDecoder.decode necessary for JDK 1.5+, where spaces are escaped to %20
- return new File( URLDecoder.decode( path, UTF_8.name() ) );
+ return new File(URLDecoder.decode(path, UTF_8.name()));
}
- protected void assertNotContainsRegex( String msg, String regex, Collection<String> coll )
- {
+ protected void assertNotContainsRegex(String msg, String regex, Collection<String> coll) {
List<String> failures = new ArrayList<>();
- Pattern pat = Pattern.compile( regex );
- for ( String value : coll )
- {
- Matcher mat = pat.matcher( value );
- if ( mat.find() )
- {
- failures.add( value );
+ Pattern pat = Pattern.compile(regex);
+ for (String value : coll) {
+ Matcher mat = pat.matcher(value);
+ if (mat.find()) {
+ failures.add(value);
}
}
- if ( !failures.isEmpty() )
- {
+ if (!failures.isEmpty()) {
StringBuilder sb = new StringBuilder();
- sb.append( msg ).append( " collection has illegal regex \"" ).append( regex ).append( "\"" );
- for ( String failure : failures )
- {
- sb.append( "\n - \"" ).append( failure ).append( "\"" );
+ sb.append(msg)
+ .append(" collection has illegal regex \"")
+ .append(regex)
+ .append("\"");
+ for (String failure : failures) {
+ sb.append("\n - \"").append(failure).append("\"");
}
- throw new AssertionFailedError( sb.toString() );
+ throw new AssertionFailedError(sb.toString());
}
}
}
diff --git a/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java b/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
index a31322b..456e602 100644
--- a/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/JarAnalyzerTest.java
@@ -1,9 +1,3 @@
-package org.apache.maven.shared.jar;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.zip.ZipException;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -22,89 +16,69 @@ import java.util.zip.ZipException;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.zip.ZipException;
/**
* Tests for the JarAnalyzer class.
*/
-public class JarAnalyzerTest
- extends AbstractJarAnalyzerTestCase
-{
+public class JarAnalyzerTest extends AbstractJarAnalyzerTestCase {
private JarAnalyzer jarAnalyzer;
-
- protected void tearDown()
- throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
- if ( jarAnalyzer != null )
- {
+ if (jarAnalyzer != null) {
jarAnalyzer.closeQuietly();
}
}
- private JarData getJarData( String filename )
- throws Exception
- {
- jarAnalyzer = getJarAnalyzer( filename );
+ private JarData getJarData(String filename) throws Exception {
+ jarAnalyzer = getJarAnalyzer(filename);
return jarAnalyzer.getJarData();
}
- private JarAnalyzer getJarAnalyzer( String filename )
- throws IOException
- {
- return new JarAnalyzer( getSampleJar( filename ) );
+ private JarAnalyzer getJarAnalyzer(String filename) throws IOException {
+ return new JarAnalyzer(getSampleJar(filename));
}
- public void testSealed()
- throws Exception
- {
- JarData jarData = getJarData( "evil-sealed-regex-1.0.jar" );
- assertTrue( jarData.isSealed() );
+ public void testSealed() throws Exception {
+ JarData jarData = getJarData("evil-sealed-regex-1.0.jar");
+ assertTrue(jarData.isSealed());
}
- public void testNotSealed()
- throws Exception
- {
- JarData jarData = getJarData( "codec.jar" );
- assertFalse( jarData.isSealed() );
+ public void testNotSealed() throws Exception {
+ JarData jarData = getJarData("codec.jar");
+ assertFalse(jarData.isSealed());
}
- public void testMissingFile()
- {
- try
- {
- jarAnalyzer = new JarAnalyzer( new File( "foo-bar-this-should-not-exist.jar" ) );
- fail( "Should not have succeeded to get the missing JAR" );
- }
- catch ( IOException e )
- {
- assertTrue( true );
+ public void testMissingFile() {
+ try {
+ jarAnalyzer = new JarAnalyzer(new File("foo-bar-this-should-not-exist.jar"));
+ fail("Should not have succeeded to get the missing JAR");
+ } catch (IOException e) {
+ assertTrue(true);
}
}
- public void testInvalidJarFile()
- throws Exception
- {
- try
- {
- getJarAnalyzer( "invalid.jar" );
- fail( "Should not have succeeded to get the invalid JAR" );
- }
- catch ( ZipException e )
- {
- assertTrue( true );
+ public void testInvalidJarFile() throws Exception {
+ try {
+ getJarAnalyzer("invalid.jar");
+ fail("Should not have succeeded to get the invalid JAR");
+ } catch (ZipException e) {
+ assertTrue(true);
}
}
- public void testCloseTwice()
- throws Exception
- {
- JarAnalyzer jarAnalyzer = getJarAnalyzer( "codec.jar" );
+ public void testCloseTwice() throws Exception {
+ JarAnalyzer jarAnalyzer = getJarAnalyzer("codec.jar");
// no exception should be thrown
jarAnalyzer.closeQuietly();
jarAnalyzer.closeQuietly();
- assertTrue( true );
+ assertTrue(true);
}
}
diff --git a/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java b/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
index aa26bef..cd2def2 100644
--- a/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/classes/ImportVisitorTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.classes;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,11 @@ package org.apache.maven.shared.jar.classes;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.classes;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
import org.apache.bcel.classfile.ClassFormatException;
import org.apache.bcel.classfile.ClassParser;
@@ -25,56 +28,45 @@ import org.apache.bcel.classfile.DescendingVisitor;
import org.apache.bcel.classfile.JavaClass;
import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-
/**
* Import Visitor Test
*/
-public class ImportVisitorTest
- extends AbstractJarAnalyzerTestCase
-{
- public void testImportsJxr()
- throws ClassFormatException, IOException
- {
- File jxrjar = getSampleJar( "jxr.jar" );
+public class ImportVisitorTest extends AbstractJarAnalyzerTestCase {
+ public void testImportsJxr() throws ClassFormatException, IOException {
+ File jxrjar = getSampleJar("jxr.jar");
String classname = "org/apache/maven/jxr/DirectoryIndexer.class";
- ClassParser classParser = new ClassParser( jxrjar.getAbsolutePath(), classname );
+ ClassParser classParser = new ClassParser(jxrjar.getAbsolutePath(), classname);
JavaClass javaClass = classParser.parse();
- ImportVisitor importVisitor = new ImportVisitor( javaClass );
- DescendingVisitor descVisitor = new DescendingVisitor( javaClass, importVisitor );
- javaClass.accept( descVisitor );
+ ImportVisitor importVisitor = new ImportVisitor(javaClass);
+ DescendingVisitor descVisitor = new DescendingVisitor(javaClass, importVisitor);
+ javaClass.accept(descVisitor);
List<String> imports = importVisitor.getImports();
- assertNotNull( "Import List", imports );
+ assertNotNull("Import List", imports);
- assertNotContainsRegex( "Import List", "[\\[\\)\\(\\;]", imports );
+ assertNotContainsRegex("Import List", "[\\[\\)\\(\\;]", imports);
- assertTrue( "imports", imports.contains( "org.apache.maven.jxr.pacman.PackageType" ) );
- assertTrue( "imports", imports.contains( "org.apache.oro.text.perl.Perl5Util" ) );
+ assertTrue("imports", imports.contains("org.apache.maven.jxr.pacman.PackageType"));
+ assertTrue("imports", imports.contains("org.apache.oro.text.perl.Perl5Util"));
}
- public void testImportsAnt()
- throws ClassFormatException, IOException
- {
- File jxrjar = getSampleJar( "ant.jar" );
+ public void testImportsAnt() throws ClassFormatException, IOException {
+ File jxrjar = getSampleJar("ant.jar");
String classname = "org/apache/tools/ant/Target.class";
- ClassParser classParser = new ClassParser( jxrjar.getAbsolutePath(), classname );
+ ClassParser classParser = new ClassParser(jxrjar.getAbsolutePath(), classname);
JavaClass javaClass = classParser.parse();
- ImportVisitor importVisitor = new ImportVisitor( javaClass );
- DescendingVisitor descVisitor = new DescendingVisitor( javaClass, importVisitor );
- javaClass.accept( descVisitor );
+ ImportVisitor importVisitor = new ImportVisitor(javaClass);
+ DescendingVisitor descVisitor = new DescendingVisitor(javaClass, importVisitor);
+ javaClass.accept(descVisitor);
List<String> imports = importVisitor.getImports();
- assertNotNull( "Import List", imports );
+ assertNotNull("Import List", imports);
- assertNotContainsRegex( "Import List", "[\\[\\)\\(\\;]", imports );
+ assertNotContainsRegex("Import List", "[\\[\\)\\(\\;]", imports);
- assertTrue( "imports", imports.contains( "org.apache.tools.ant.Location" ) );
- assertTrue( "imports", imports.contains( "org.apache.tools.ant.Task" ) );
+ assertTrue("imports", imports.contains("org.apache.tools.ant.Location"));
+ assertTrue("imports", imports.contains("org.apache.tools.ant.Task"));
}
}
diff --git a/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java b/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
index 4fa57d9..60252b5 100644
--- a/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/classes/JarClassesAnalyzerTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.classes;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,165 +16,133 @@ package org.apache.maven.shared.jar.classes;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
-import org.apache.maven.shared.jar.JarAnalyzer;
+package org.apache.maven.shared.jar.classes;
import java.io.File;
+import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
+import org.apache.maven.shared.jar.JarAnalyzer;
/**
* JarAnalyzer Classes Test Case
*/
-public class JarClassesAnalyzerTest
- extends AbstractJarAnalyzerTestCase
-{
+public class JarClassesAnalyzerTest extends AbstractJarAnalyzerTestCase {
private JarClassesAnalysis analyzer;
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- analyzer = (JarClassesAnalysis) lookup( JarClassesAnalysis.class.getName() );
+ analyzer = (JarClassesAnalysis) lookup(JarClassesAnalysis.class.getName());
}
- public void testAnalyzeJXR()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "jxr.jar" );
+ public void testAnalyzeJXR() throws Exception {
+ JarClasses jclass = getJarClasses("jxr.jar");
- assertFalse( "classes.imports.length > 0", jclass.getImports().isEmpty() );
- assertFalse( "classes.packages.length > 0", jclass.getPackages().isEmpty() );
- assertFalse( "classes.methods.length > 0", jclass.getMethods().isEmpty() );
+ assertFalse("classes.imports.length > 0", jclass.getImports().isEmpty());
+ assertFalse("classes.packages.length > 0", jclass.getPackages().isEmpty());
+ assertFalse("classes.methods.length > 0", jclass.getMethods().isEmpty());
- assertNotContainsRegex( "Import List", "[\\[\\)\\(\\;]", jclass.getImports() );
+ assertNotContainsRegex("Import List", "[\\[\\)\\(\\;]", jclass.getImports());
// TODO: test for classes, methods, etc.
- assertTrue( "classes.imports", jclass.getImports().contains( "org.apache.maven.jxr.JXR" ) );
- assertTrue( "classes.imports", jclass.getImports().contains( "org.apache.oro.text.perl.Perl5Util" ) );
- assertTrue( "classes.packages", jclass.getPackages().contains( "org.apache.maven.jxr.pacman" ) );
+ assertTrue("classes.imports", jclass.getImports().contains("org.apache.maven.jxr.JXR"));
+ assertTrue("classes.imports", jclass.getImports().contains("org.apache.oro.text.perl.Perl5Util"));
+ assertTrue("classes.packages", jclass.getPackages().contains("org.apache.maven.jxr.pacman"));
}
- public void testAnalyzeANT()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "ant.jar" );
+ public void testAnalyzeANT() throws Exception {
+ JarClasses jclass = getJarClasses("ant.jar");
- assertFalse( "classes.imports.length > 0", jclass.getImports().isEmpty() );
- assertFalse( "classes.packages.length > 0", jclass.getPackages().isEmpty() );
- assertFalse( "classes.methods.length > 0", jclass.getMethods().isEmpty() );
+ assertFalse("classes.imports.length > 0", jclass.getImports().isEmpty());
+ assertFalse("classes.packages.length > 0", jclass.getPackages().isEmpty());
+ assertFalse("classes.methods.length > 0", jclass.getMethods().isEmpty());
- assertNotContainsRegex( "Import List", "[\\[\\)\\(\\;]", jclass.getImports() );
+ assertNotContainsRegex("Import List", "[\\[\\)\\(\\;]", jclass.getImports());
- assertTrue( "classes.imports", jclass.getImports().contains( "java.util.zip.GZIPInputStream" ) );
- assertTrue( "classes.imports", jclass.getImports().contains( "org.apache.tools.ant.XmlLogger$TimedElement" ) );
- assertTrue( "classes.imports", jclass.getImports().contains( "org.apache.tools.mail.MailMessage" ) );
- assertTrue( "classes.packages", jclass.getPackages().contains( "org.apache.tools.ant" ) );
- assertTrue( "classes.packages", jclass.getPackages().contains( "org.apache.tools.bzip2" ) );
+ assertTrue("classes.imports", jclass.getImports().contains("java.util.zip.GZIPInputStream"));
+ assertTrue("classes.imports", jclass.getImports().contains("org.apache.tools.ant.XmlLogger$TimedElement"));
+ assertTrue("classes.imports", jclass.getImports().contains("org.apache.tools.mail.MailMessage"));
+ assertTrue("classes.packages", jclass.getPackages().contains("org.apache.tools.ant"));
+ assertTrue("classes.packages", jclass.getPackages().contains("org.apache.tools.bzip2"));
}
- public void testAnalyzeJarWithInvalidClassFile()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "invalid-class-file.jar" );
+ public void testAnalyzeJarWithInvalidClassFile() throws Exception {
+ JarClasses jclass = getJarClasses("invalid-class-file.jar");
// Doesn't fail, as exceptions are ignored.
- assertTrue( jclass.getClassNames().isEmpty() );
- assertTrue( jclass.getPackages().isEmpty() );
- assertTrue( jclass.getImports().isEmpty() );
- assertNull( jclass.getJdkRevision() );
- assertTrue( jclass.getMethods().isEmpty() );
+ assertTrue(jclass.getClassNames().isEmpty());
+ assertTrue(jclass.getPackages().isEmpty());
+ assertTrue(jclass.getImports().isEmpty());
+ assertNull(jclass.getJdkRevision());
+ assertTrue(jclass.getMethods().isEmpty());
}
- public void testAnalyzeJarWithDebug()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.4-debug.jar" );
+ public void testAnalyzeJarWithDebug() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.4-debug.jar");
- assertTrue( "has debug", jclass.isDebugPresent() );
+ assertTrue("has debug", jclass.isDebugPresent());
}
- public void testAnalyzeJarWithoutDebug()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.4.jar" );
+ public void testAnalyzeJarWithoutDebug() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.4.jar");
- assertFalse( "no debug present", jclass.isDebugPresent() );
+ assertFalse("no debug present", jclass.isDebugPresent());
}
- public void testAnalyzeJarVersion18()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.8.jar" );
+ public void testAnalyzeJarVersion18() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.8.jar");
- assertEquals( "jdkrevision", "1.8", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.8", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion17()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.7.jar" );
+ public void testAnalyzeJarVersion17() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.7.jar");
- assertEquals( "jdkrevision", "1.7", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.7", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion16()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.6.jar" );
+ public void testAnalyzeJarVersion16() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.6.jar");
- assertEquals( "jdkrevision", "1.6", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.6", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion15()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.5.jar" );
+ public void testAnalyzeJarVersion15() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.5.jar");
- assertEquals( "jdkrevision", "1.5", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.5", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion14()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.4.jar" );
+ public void testAnalyzeJarVersion14() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.4.jar");
- assertEquals( "jdkrevision", "1.4", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.4", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion13()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.3.jar" );
+ public void testAnalyzeJarVersion13() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.3.jar");
- assertEquals( "jdkrevision", "1.3", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.3", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion12()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.2.jar" );
+ public void testAnalyzeJarVersion12() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.2.jar");
- assertEquals( "jdkrevision", "1.2", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.2", jclass.getJdkRevision());
}
- public void testAnalyzeJarVersion11()
- throws Exception
- {
- JarClasses jclass = getJarClasses( "helloworld-1.1.jar" );
+ public void testAnalyzeJarVersion11() throws Exception {
+ JarClasses jclass = getJarClasses("helloworld-1.1.jar");
- assertEquals( "jdkrevision", "1.1", jclass.getJdkRevision() );
+ assertEquals("jdkrevision", "1.1", jclass.getJdkRevision());
}
- private JarClasses getJarClasses( String filename )
- throws Exception
- {
- File file = getSampleJar( filename );
+ private JarClasses getJarClasses(String filename) throws Exception {
+ File file = getSampleJar(filename);
- JarClasses jclass = analyzer.analyze( new JarAnalyzer( file ) );
- assertNotNull( "JarClasses", jclass );
+ JarClasses jclass = analyzer.analyze(new JarAnalyzer(file));
+ assertNotNull("JarClasses", jclass);
return jclass;
}
diff --git a/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java b/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
index 9c52a08..ca8ed21 100644
--- a/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/identification/JarIdentificationAnalyzerTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,44 +16,38 @@ package org.apache.maven.shared.jar.identification;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
-import org.apache.maven.shared.jar.JarAnalyzer;
+package org.apache.maven.shared.jar.identification;
import java.io.File;
+import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
+import org.apache.maven.shared.jar.JarAnalyzer;
/**
* JarAnalyzer Taxon Analyzer Test Case
*
* TODO test the exposers individually instead of in aggregate here (and test the normalize, etc. methods here instead with controlled exposers)
*/
-public class JarIdentificationAnalyzerTest
- extends AbstractJarAnalyzerTestCase
-{
- private JarIdentification getJarTaxon( String filename )
- throws Exception
- {
- File jarfile = getSampleJar( filename );
+public class JarIdentificationAnalyzerTest extends AbstractJarAnalyzerTestCase {
+ private JarIdentification getJarTaxon(String filename) throws Exception {
+ File jarfile = getSampleJar(filename);
JarIdentificationAnalysis analyzer =
- (JarIdentificationAnalysis) lookup( JarIdentificationAnalysis.class.getName() );
- JarIdentification taxon = analyzer.analyze( new JarAnalyzer( jarfile ) );
- assertNotNull( "JarIdentification", taxon );
+ (JarIdentificationAnalysis) lookup(JarIdentificationAnalysis.class.getName());
+ JarIdentification taxon = analyzer.analyze(new JarAnalyzer(jarfile));
+ assertNotNull("JarIdentification", taxon);
return taxon;
}
- public void testTaxonAnalyzerWithJXR()
- throws Exception
- {
- JarIdentification taxon = getJarTaxon( "jxr.jar" );
+ public void testTaxonAnalyzerWithJXR() throws Exception {
+ JarIdentification taxon = getJarTaxon("jxr.jar");
- assertEquals( "identification.groupId", "org.apache.maven", taxon.getGroupId() );
- assertEquals( "identification.artifactId", "maven-jxr", taxon.getArtifactId() );
- assertEquals( "identification.version", "1.1-SNAPSHOT", taxon.getVersion() );
- assertEquals( "identification.name", "Maven JXR", taxon.getName() );
- assertEquals( "identification.vendor", "Apache Software Foundation", taxon.getVendor() );
+ assertEquals("identification.groupId", "org.apache.maven", taxon.getGroupId());
+ assertEquals("identification.artifactId", "maven-jxr", taxon.getArtifactId());
+ assertEquals("identification.version", "1.1-SNAPSHOT", taxon.getVersion());
+ assertEquals("identification.name", "Maven JXR", taxon.getName());
+ assertEquals("identification.vendor", "Apache Software Foundation", taxon.getVendor());
// TODO assert potentials too
}
@@ -65,33 +57,30 @@ public class JarIdentificationAnalyzerTest
*
* @throws Exception failures
*/
- public void testTaxonAnalyzerWithCODEC()
- throws Exception
- {
- JarIdentification taxon = getJarTaxon( "codec.jar" );
+ public void testTaxonAnalyzerWithCODEC() throws Exception {
+ JarIdentification taxon = getJarTaxon("codec.jar");
- assertEquals( "identification.groupId", "org.apache.commons.codec", taxon.getGroupId() );
- assertEquals( "identification.artifactId", "codec", taxon.getArtifactId() );
+ assertEquals("identification.groupId", "org.apache.commons.codec", taxon.getGroupId());
+ assertEquals("identification.artifactId", "codec", taxon.getArtifactId());
// TODO fix assertion
- // assertEquals( "identification.version", "codec_release_1_0_0_interim_20030519095102_build", identification.getVersion() );
- assertEquals( "identification.version", "20030519", taxon.getVersion() );
- assertEquals( "identification.name", "codec", taxon.getName() );
- assertNull( "identification.vendor", taxon.getVendor() );
+ // assertEquals( "identification.version", "codec_release_1_0_0_interim_20030519095102_build",
+ // identification.getVersion() );
+ assertEquals("identification.version", "20030519", taxon.getVersion());
+ assertEquals("identification.name", "codec", taxon.getName());
+ assertNull("identification.vendor", taxon.getVendor());
// TODO assert potentials too
}
- public void testTaxonAnalyzerWithANT()
- throws Exception
- {
- JarIdentification taxon = getJarTaxon( "ant.jar" );
+ public void testTaxonAnalyzerWithANT() throws Exception {
+ JarIdentification taxon = getJarTaxon("ant.jar");
- assertEquals( "identification.groupId", "org.apache.tools.ant", taxon.getGroupId() );
- assertEquals( "identification.artifactId", "ant", taxon.getArtifactId() );
- assertEquals( "identification.version", "1.6.5", taxon.getVersion() );
+ assertEquals("identification.groupId", "org.apache.tools.ant", taxon.getGroupId());
+ assertEquals("identification.artifactId", "ant", taxon.getArtifactId());
+ assertEquals("identification.version", "1.6.5", taxon.getVersion());
// TODO fix assertion
// assertEquals( "identification.name", "Apache Ant", identification.getName() );
- assertEquals( "identification.vendor", "Apache Software Foundation", taxon.getVendor() );
+ assertEquals("identification.vendor", "Apache Software Foundation", taxon.getVendor());
// TODO assert potentials too
}
diff --git a/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java b/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
index f90e148..9940d07 100644
--- a/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
+++ b/src/test/java/org/apache/maven/shared/jar/identification/exposers/EmbeddedMavenModelExposerTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jar.identification.exposers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,70 +16,64 @@ package org.apache.maven.shared.jar.identification.exposers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jar.identification.exposers;
+
+import java.io.File;
import org.apache.maven.shared.jar.AbstractJarAnalyzerTestCase;
import org.apache.maven.shared.jar.JarAnalyzer;
import org.apache.maven.shared.jar.identification.JarIdentification;
-import java.io.File;
-
-
/**
* Test Case for Embedded Maven Model Taxon Data.
*/
-public class EmbeddedMavenModelExposerTest
- extends AbstractJarAnalyzerTestCase
-{
- public void testExposerWithParent()
- throws Exception
- {
- File file = getSampleJar( "test1.jar" );
+public class EmbeddedMavenModelExposerTest extends AbstractJarAnalyzerTestCase {
+ public void testExposerWithParent() throws Exception {
+ File file = getSampleJar("test1.jar");
JarIdentification identification = new JarIdentification();
EmbeddedMavenModelExposer exposer = new EmbeddedMavenModelExposer();
- exposer.expose( identification, new JarAnalyzer( file ) );
+ exposer.expose(identification, new JarAnalyzer(file));
- assertEquals( 1, identification.getPotentialGroupIds().size() );
- assertEquals( "test", identification.getPotentialGroupIds().get( 0 ) );
+ assertEquals(1, identification.getPotentialGroupIds().size());
+ assertEquals("test", identification.getPotentialGroupIds().get(0));
- assertEquals( 1, identification.getPotentialArtifactIds().size() );
- assertEquals( "test1", identification.getPotentialArtifactIds().get( 0 ) );
+ assertEquals(1, identification.getPotentialArtifactIds().size());
+ assertEquals("test1", identification.getPotentialArtifactIds().get(0));
- assertEquals( 1, identification.getPotentialVersions().size() );
- assertEquals( "1.1-SNAPSHOT", identification.getPotentialVersions().get( 0 ) );
+ assertEquals(1, identification.getPotentialVersions().size());
+ assertEquals("1.1-SNAPSHOT", identification.getPotentialVersions().get(0));
}
- public void testExposerWithJXR()
- throws Exception
- {
- File file = getSampleJar( "jxr.jar" );
+ public void testExposerWithJXR() throws Exception {
+ File file = getSampleJar("jxr.jar");
JarIdentification identification = new JarIdentification();
EmbeddedMavenModelExposer exposer = new EmbeddedMavenModelExposer();
- exposer.expose( identification, new JarAnalyzer( file ) );
+ exposer.expose(identification, new JarAnalyzer(file));
- assertFalse( "exposer.groupIds", identification.getPotentialGroupIds().isEmpty() );
- assertFalse( "exposer.artifactIds", identification.getPotentialArtifactIds().isEmpty() );
- assertFalse( "exposer.versions", identification.getPotentialVersions().isEmpty() );
+ assertFalse("exposer.groupIds", identification.getPotentialGroupIds().isEmpty());
+ assertFalse(
+ "exposer.artifactIds", identification.getPotentialArtifactIds().isEmpty());
+ assertFalse("exposer.versions", identification.getPotentialVersions().isEmpty());
// TODO test others
}
- public void testExposerWithANT()
- throws Exception
- {
- File file = getSampleJar( "ant.jar" );
+ public void testExposerWithANT() throws Exception {
+ File file = getSampleJar("ant.jar");
JarIdentification identification = new JarIdentification();
EmbeddedMavenModelExposer exposer = new EmbeddedMavenModelExposer();
- exposer.expose( identification, new JarAnalyzer( file ) );
+ exposer.expose(identification, new JarAnalyzer(file));
- assertTrue( "exposer.groupIds", identification.getPotentialGroupIds().isEmpty() );
- assertTrue( "exposer.artifactIds", identification.getPotentialArtifactIds().isEmpty() );
- assertTrue( "exposer.versions", identification.getPotentialVersions().isEmpty() );
+ assertTrue("exposer.groupIds", identification.getPotentialGroupIds().isEmpty());
+ assertTrue(
+ "exposer.artifactIds", identification.getPotentialArtifactIds().isEmpty());
+ assertTrue("exposer.versions", identification.getPotentialVersions().isEmpty());
// TODO test others
}