You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2023/04/08 17:54:12 UTC
[maven-jarsigner] 01/01: Update parent POM to 39
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch 39
in repository https://gitbox.apache.org/repos/asf/maven-jarsigner.git
commit a7d8f27ee4d0c86cba97d09756e7ff69109ea7a3
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sat Apr 8 13:54:00 2023 -0400
Update parent POM to 39
---
pom.xml | 15 +-
.../shared/jarsigner/AbstractJarSignerRequest.java | 105 +++++------
.../CommandLineConfigurationException.java | 34 ++--
.../maven/shared/jarsigner/DefaultJarSigner.java | 85 ++++-----
.../apache/maven/shared/jarsigner/JarSigner.java | 24 ++-
.../jarsigner/JarSignerCommandLineBuilder.java | 207 ++++++++++-----------
.../maven/shared/jarsigner/JarSignerRequest.java | 53 ++++--
.../shared/jarsigner/JarSignerSignRequest.java | 62 +++---
.../maven/shared/jarsigner/JarSignerUtil.java | 158 ++++++++--------
.../shared/jarsigner/JarSignerVerifyRequest.java | 28 ++-
.../shared/jarsigner/AbstractJarSignerTest.java | 38 ++--
.../maven/shared/jarsigner/JarSignerUtilTest.java | 75 ++++----
.../maven/shared/jarsigner/SimpleJarSignTest.java | 76 ++++----
13 files changed, 503 insertions(+), 457 deletions(-)
diff --git a/pom.xml b/pom.xml
index efe69e6..1a00217 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
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-components</artifactId>
- <version>34</version>
+ <version>39</version>
<relativePath />
</parent>
@@ -36,8 +36,8 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-jarsigner.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-jarsigner.git</developerConnection>
- <url>https://github.com/apache/maven-jarsigner/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/maven-jarsigner/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>jira</system>
@@ -56,8 +56,7 @@
<properties>
<surefire.version>2.21.0</surefire.version>
- <mavenVersion>3.0</mavenVersion>
- <javaVersion>7</javaVersion>
+ <mavenVersion>3.2.5</mavenVersion>
<project.build.outputTimestamp>2020-04-04T09:03:59Z</project.build.outputTimestamp>
</properties>
@@ -65,12 +64,13 @@
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-utils</artifactId>
- <version>3.2.1</version>
+ <version>3.3.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-annotations</artifactId>
+ <version>2.1.1</version>
</dependency>
<dependency>
@@ -109,7 +109,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
- <version>3.0.0</version>
+ <version>3.3.0</version>
</plugin>
</plugins>
</pluginManagement>
@@ -117,6 +117,7 @@
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
+ <version>2.1.1</version>
<executions>
<execution>
<id>create-component-descriptor</id>
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java b/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
index 1fb0527..00db87b 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -19,20 +37,17 @@ package org.apache.maven.shared.jarsigner;
* under the License.
*/
-import org.apache.maven.shared.utils.cli.javatool.AbstractJavaToolRequest;
-
import java.io.File;
+import org.apache.maven.shared.utils.cli.javatool.AbstractJavaToolRequest;
+
/**
* Specifies the commons parameters used to control a jar signer invocation.
*
* @author Tony Chemit
* @since 1.0
*/
-public abstract class AbstractJarSignerRequest
- extends AbstractJavaToolRequest
- implements JarSignerRequest
-{
+public abstract class AbstractJarSignerRequest extends AbstractJavaToolRequest implements JarSignerRequest {
/**
* See <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
*/
@@ -102,208 +117,182 @@ public abstract class AbstractJarSignerRequest
/**
* {@inheritDoc}
*/
- public boolean isVerbose()
- {
+ public boolean isVerbose() {
return verbose;
}
/**
* {@inheritDoc}
*/
- public String getKeystore()
- {
+ public String getKeystore() {
return keystore;
}
/**
* {@inheritDoc}
*/
- public String getStoretype()
- {
+ public String getStoretype() {
return storetype;
}
/**
* {@inheritDoc}
*/
- public String getStorepass()
- {
+ public String getStorepass() {
return storepass;
}
/**
* {@inheritDoc}
*/
- public String getAlias()
- {
+ public String getAlias() {
return alias;
}
/**
* {@inheritDoc}
*/
- public String getProviderName()
- {
+ public String getProviderName() {
return providerName;
}
/**
* {@inheritDoc}
*/
- public String getProviderClass()
- {
+ public String getProviderClass() {
return providerClass;
}
/**
* {@inheritDoc}
*/
- public String getProviderArg()
- {
+ public String getProviderArg() {
return providerArg;
}
/**
* {@inheritDoc}
*/
- public String getMaxMemory()
- {
+ public String getMaxMemory() {
return maxMemory;
}
/**
* {@inheritDoc}
*/
- public String[] getArguments()
- {
+ public String[] getArguments() {
return arguments;
}
/**
* {@inheritDoc}
*/
- public File getWorkingDirectory()
- {
+ public File getWorkingDirectory() {
return workingDirectory;
}
/**
* {@inheritDoc}
*/
- public File getArchive()
- {
+ public File getArchive() {
return archive;
}
/**
* {@inheritDoc}
*/
- public boolean isProtectedAuthenticationPath()
- {
+ public boolean isProtectedAuthenticationPath() {
return protectedAuthenticationPath;
}
/**
* {@inheritDoc}
*/
- public void setVerbose( boolean verbose )
- {
+ public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
/**
* {@inheritDoc}
*/
- public void setKeystore( String keystore )
- {
+ public void setKeystore(String keystore) {
this.keystore = keystore;
}
/**
* {@inheritDoc}
*/
- public void setStoretype( String storetype )
- {
+ public void setStoretype(String storetype) {
this.storetype = storetype;
}
/**
* {@inheritDoc}
*/
- public void setStorepass( String storepass )
- {
+ public void setStorepass(String storepass) {
this.storepass = storepass;
}
/**
* {@inheritDoc}
*/
- public void setProviderName( String providerName )
- {
+ public void setProviderName(String providerName) {
this.providerName = providerName;
}
/**
* {@inheritDoc}
*/
- public void setProviderClass( String providerClass )
- {
+ public void setProviderClass(String providerClass) {
this.providerClass = providerClass;
}
/**
* {@inheritDoc}
*/
- public void setProviderArg( String providerArg )
- {
+ public void setProviderArg(String providerArg) {
this.providerArg = providerArg;
}
/**
* {@inheritDoc}
*/
- public void setAlias( String alias )
- {
+ public void setAlias(String alias) {
this.alias = alias;
}
/**
* {@inheritDoc}
*/
- public void setMaxMemory( String maxMemory )
- {
+ public void setMaxMemory(String maxMemory) {
this.maxMemory = maxMemory;
}
/**
* {@inheritDoc}
*/
- public void setArguments( String... arguments )
- {
+ public void setArguments(String... arguments) {
this.arguments = arguments;
}
/**
* {@inheritDoc}
*/
- public void setWorkingDirectory( File workingDirectory )
- {
+ public void setWorkingDirectory(File workingDirectory) {
this.workingDirectory = workingDirectory;
}
/**
* {@inheritDoc}
*/
- public void setArchive( File archive )
- {
+ public void setArchive(File archive) {
this.archive = archive;
}
/**
* {@inheritDoc}
*/
- public void setProtectedAuthenticationPath( boolean protect )
- {
+ public void setProtectedAuthenticationPath(boolean protect) {
this.protectedAuthenticationPath = protect;
}
}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java b/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
index d44a756..d1aa5f7 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -25,9 +43,7 @@ package org.apache.maven.shared.jarsigner;
* @author Tony Chemit
* @since 1.0
*/
-public class CommandLineConfigurationException
- extends Exception
-{
+public class CommandLineConfigurationException extends Exception {
private static final long serialVersionUID = 1L;
@@ -37,9 +53,8 @@ public class CommandLineConfigurationException
* @param message The detail message for this exception, may be <code>null</code>.
* @param cause The nested exception, may be <code>null</code>.
*/
- public CommandLineConfigurationException( String message, Throwable cause )
- {
- super( message, cause );
+ public CommandLineConfigurationException(String message, Throwable cause) {
+ super(message, cause);
}
/**
@@ -47,10 +62,7 @@ public class CommandLineConfigurationException
*
* @param message The detail message for this exception, may be <code>null</code>.
*/
- public CommandLineConfigurationException( String message )
- {
- super( message );
+ public CommandLineConfigurationException(String message) {
+ super(message);
}
-
}
-
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java b/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
index e789674..7141f30 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -31,73 +49,52 @@ import org.codehaus.plexus.component.annotations.Component;
* @author Tony Chemit
* @since 1.0
*/
-@Component( role = JarSigner.class, hint = "default" )
-public class DefaultJarSigner
- extends AbstractJavaTool<JarSignerRequest>
- implements JarSigner
-{
+@Component(role = JarSigner.class, hint = "default")
+public class DefaultJarSigner extends AbstractJavaTool<JarSignerRequest> implements JarSigner {
- public DefaultJarSigner()
- {
- super( "jarsigner" );
+ public DefaultJarSigner() {
+ super("jarsigner");
}
@Override
- protected Commandline createCommandLine( JarSignerRequest request, String javaToolFile )
- throws JavaToolException
- {
+ protected Commandline createCommandLine(JarSignerRequest request, String javaToolFile) throws JavaToolException {
JarSignerCommandLineBuilder cliBuilder = new JarSignerCommandLineBuilder();
- cliBuilder.setLogger( getLogger() );
- cliBuilder.setJarSignerFile( javaToolFile );
- try
- {
- Commandline cli = cliBuilder.build( request );
- if ( request.isVerbose() )
- {
- getLogger().info( cli.toString() );
- }
- else
- {
- getLogger().debug( cli.toString() );
+ cliBuilder.setLogger(getLogger());
+ cliBuilder.setJarSignerFile(javaToolFile);
+ try {
+ Commandline cli = cliBuilder.build(request);
+ if (request.isVerbose()) {
+ getLogger().info(cli.toString());
+ } else {
+ getLogger().debug(cli.toString());
}
return cli;
- }
- catch ( CommandLineConfigurationException e )
- {
- throw new JavaToolException( "Error configuring command-line. Reason: " + e.getMessage(), e );
+ } catch (CommandLineConfigurationException e) {
+ throw new JavaToolException("Error configuring command-line. Reason: " + e.getMessage(), e);
}
}
- protected StreamConsumer createSystemOutStreamConsumer( JarSignerRequest request )
- {
+ protected StreamConsumer createSystemOutStreamConsumer(JarSignerRequest request) {
StreamConsumer systemOut = request.getSystemOutStreamConsumer();
- if ( systemOut == null )
- {
+ if (systemOut == null) {
final boolean verbose = request.isVerbose();
- systemOut = new StreamConsumer()
- {
+ systemOut = new StreamConsumer() {
/**
* {@inheritDoc}
*/
- public void consumeLine( final String line )
- {
- if ( verbose )
- {
- getLogger().info( line );
- }
- else
- {
- getLogger().debug( line );
+ public void consumeLine(final String line) {
+ if (verbose) {
+ getLogger().info(line);
+ } else {
+ getLogger().debug(line);
}
}
-
};
}
return systemOut;
}
-
}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
index 9cdc534..f193123 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -27,8 +45,4 @@ import org.apache.maven.shared.utils.cli.javatool.JavaTool;
* @author Tony Chemit
* @since 1.0
*/
-public interface JarSigner
- extends JavaTool<JarSignerRequest>
-{
-
-}
+public interface JarSigner extends JavaTool<JarSignerRequest> {}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
index 0be0308..5ce1bc7 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -19,214 +37,179 @@ package org.apache.maven.shared.jarsigner;
* under the License.
*/
+import java.io.File;
+import java.io.IOException;
+
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Arg;
import org.apache.maven.shared.utils.cli.Commandline;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
-import java.io.File;
-import java.io.IOException;
-
/**
* To build the command line for a given {@link JarSignerRequest}.
*
* @author Tony Chemit
* @since 1.0
*/
-public class JarSignerCommandLineBuilder
-{
- private static final Logger DEFAULT_LOGGER = new ConsoleLogger( 0, JarSignerCommandLineBuilder.class.getName() );
+public class JarSignerCommandLineBuilder {
+ private static final Logger DEFAULT_LOGGER = new ConsoleLogger(0, JarSignerCommandLineBuilder.class.getName());
private Logger logger = DEFAULT_LOGGER;
private String jarSignerFile;
- public Commandline build( JarSignerRequest request )
- throws CommandLineConfigurationException
- {
- try
- {
+ public Commandline build(JarSignerRequest request) throws CommandLineConfigurationException {
+ try {
checkRequiredState();
- }
- catch ( IOException e )
- {
- throw new CommandLineConfigurationException( e.getMessage(), e );
+ } catch (IOException e) {
+ throw new CommandLineConfigurationException(e.getMessage(), e);
}
Commandline cli = new Commandline();
- cli.setExecutable( jarSignerFile );
+ cli.setExecutable(jarSignerFile);
- cli.setWorkingDirectory( request.getWorkingDirectory() );
+ cli.setWorkingDirectory(request.getWorkingDirectory());
- if ( request.isVerbose() )
- {
- cli.createArg().setValue( "-verbose" );
+ if (request.isVerbose()) {
+ cli.createArg().setValue("-verbose");
}
String keystore = request.getKeystore();
- if ( !StringUtils.isEmpty( keystore ) )
- {
- cli.createArg().setValue( "-keystore" );
- cli.createArg().setValue( keystore );
+ if (!StringUtils.isEmpty(keystore)) {
+ cli.createArg().setValue("-keystore");
+ cli.createArg().setValue(keystore);
}
String storepass = request.getStorepass();
- if ( !StringUtils.isEmpty( storepass ) )
- {
- cli.createArg().setValue( "-storepass" );
+ if (!StringUtils.isEmpty(storepass)) {
+ cli.createArg().setValue("-storepass");
Arg arg = cli.createArg();
- arg.setValue( storepass );
- arg.setMask( true );
+ arg.setValue(storepass);
+ arg.setMask(true);
}
String storetype = request.getStoretype();
- if ( !StringUtils.isEmpty( storetype ) )
- {
- cli.createArg().setValue( "-storetype" );
- cli.createArg().setValue( storetype );
+ if (!StringUtils.isEmpty(storetype)) {
+ cli.createArg().setValue("-storetype");
+ cli.createArg().setValue(storetype);
}
String providerName = request.getProviderName();
- if ( !StringUtils.isEmpty( providerName ) )
- {
- cli.createArg().setValue( "-providerName" );
- cli.createArg().setValue( providerName );
+ if (!StringUtils.isEmpty(providerName)) {
+ cli.createArg().setValue("-providerName");
+ cli.createArg().setValue(providerName);
}
String providerClass = request.getProviderClass();
- if ( !StringUtils.isEmpty( providerClass ) )
- {
- cli.createArg().setValue( "-providerClass" );
- cli.createArg().setValue( providerClass );
+ if (!StringUtils.isEmpty(providerClass)) {
+ cli.createArg().setValue("-providerClass");
+ cli.createArg().setValue(providerClass);
}
String providerArg = request.getProviderArg();
- if ( !StringUtils.isEmpty( providerArg ) )
- {
- cli.createArg().setValue( "-providerArg" );
- cli.createArg().setValue( providerArg );
+ if (!StringUtils.isEmpty(providerArg)) {
+ cli.createArg().setValue("-providerArg");
+ cli.createArg().setValue(providerArg);
}
- if ( request.isProtectedAuthenticationPath() )
- {
- cli.createArg().setValue( "-protected" );
+ if (request.isProtectedAuthenticationPath()) {
+ cli.createArg().setValue("-protected");
}
String maxMemory = request.getMaxMemory();
- if ( StringUtils.isNotEmpty( maxMemory ) )
- {
- cli.createArg().setValue( "-J-Xmx" + maxMemory );
+ if (StringUtils.isNotEmpty(maxMemory)) {
+ cli.createArg().setValue("-J-Xmx" + maxMemory);
}
String[] arguments = request.getArguments();
- if ( arguments != null )
- {
- cli.addArguments( arguments );
+ if (arguments != null) {
+ cli.addArguments(arguments);
}
- if ( request instanceof JarSignerSignRequest )
- {
- build( (JarSignerSignRequest) request, cli );
+ if (request instanceof JarSignerSignRequest) {
+ build((JarSignerSignRequest) request, cli);
}
- if ( request instanceof JarSignerVerifyRequest )
- {
- build( (JarSignerVerifyRequest) request, cli );
+ if (request instanceof JarSignerVerifyRequest) {
+ build((JarSignerVerifyRequest) request, cli);
}
- cli.createArg().setFile( request.getArchive() );
+ cli.createArg().setFile(request.getArchive());
String alias = request.getAlias();
- if ( !StringUtils.isEmpty( alias ) )
- {
- cli.createArg().setValue( alias );
+ if (!StringUtils.isEmpty(alias)) {
+ cli.createArg().setValue(alias);
}
return cli;
}
- public void setLogger( Logger logger )
- {
+ public void setLogger(Logger logger) {
this.logger = logger;
}
- public void setJarSignerFile( String jarSignerFile )
- {
+ public void setJarSignerFile(String jarSignerFile) {
this.jarSignerFile = jarSignerFile;
}
- protected void checkRequiredState()
- throws IOException
- {
- if ( logger == null )
- {
- throw new IllegalStateException( "A logger instance is required." );
+ protected void checkRequiredState() throws IOException {
+ if (logger == null) {
+ throw new IllegalStateException("A logger instance is required.");
}
- if ( jarSignerFile == null )
- {
- throw new IllegalStateException( "A jarSigner file is required." );
+ if (jarSignerFile == null) {
+ throw new IllegalStateException("A jarSigner file is required.");
}
}
- protected void build( JarSignerSignRequest request, Commandline cli )
- {
+ protected void build(JarSignerSignRequest request, Commandline cli) {
String keypass = request.getKeypass();
- if ( !StringUtils.isEmpty( keypass ) )
- {
- cli.createArg().setValue( "-keypass" );
+ if (!StringUtils.isEmpty(keypass)) {
+ cli.createArg().setValue("-keypass");
Arg arg = cli.createArg();
- arg.setValue( keypass );
- arg.setMask( true );
+ arg.setValue(keypass);
+ arg.setMask(true);
}
String sigfile = request.getSigfile();
- if ( !StringUtils.isEmpty( sigfile ) )
- {
- cli.createArg().setValue( "-sigfile" );
- cli.createArg().setValue( sigfile );
+ if (!StringUtils.isEmpty(sigfile)) {
+ cli.createArg().setValue("-sigfile");
+ cli.createArg().setValue(sigfile);
}
String tsaLocation = request.getTsaLocation();
- if ( StringUtils.isNotBlank( tsaLocation ) )
- {
- cli.createArg().setValue( "-tsa" );
- cli.createArg().setValue( tsaLocation );
+ if (StringUtils.isNotBlank(tsaLocation)) {
+ cli.createArg().setValue("-tsa");
+ cli.createArg().setValue(tsaLocation);
}
String tsaAlias = request.getTsaAlias();
- if ( StringUtils.isNotBlank( tsaAlias ) )
- {
- cli.createArg().setValue( "-tsacert" );
- cli.createArg().setValue( tsaAlias );
+ if (StringUtils.isNotBlank(tsaAlias)) {
+ cli.createArg().setValue("-tsacert");
+ cli.createArg().setValue(tsaAlias);
}
File signedjar = request.getSignedjar();
- if ( signedjar != null )
- {
- cli.createArg().setValue( "-signedjar" );
- cli.createArg().setValue( signedjar.getAbsolutePath() );
+ if (signedjar != null) {
+ cli.createArg().setValue("-signedjar");
+ cli.createArg().setValue(signedjar.getAbsolutePath());
}
-
+
final File certchain = request.getCertchain();
- if ( certchain != null )
- {
- cli.createArg().setValue( "-certchain" );
- cli.createArg().setValue( certchain.getAbsolutePath() );
+ if (certchain != null) {
+ cli.createArg().setValue("-certchain");
+ cli.createArg().setValue(certchain.getAbsolutePath());
}
}
- protected void build( JarSignerVerifyRequest request, Commandline cli )
- throws CommandLineConfigurationException
- {
- cli.createArg( true ).setValue( "-verify" );
+ protected void build(JarSignerVerifyRequest request, Commandline cli) throws CommandLineConfigurationException {
+ cli.createArg(true).setValue("-verify");
- if ( request.isCerts() )
- {
- cli.createArg().setValue( "-certs" );
+ if (request.isCerts()) {
+ cli.createArg().setValue("-certs");
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
index 1ef819d..4f217f7 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -19,19 +37,17 @@ package org.apache.maven.shared.jarsigner;
* under the License.
*/
-import org.apache.maven.shared.utils.cli.javatool.JavaToolRequest;
-
import java.io.File;
+import org.apache.maven.shared.utils.cli.javatool.JavaToolRequest;
+
/**
* Specifies the common parameters used to control a JarSigner tool invocation.
*
* @author Tony Chemit
* @since 1.0
*/
-public interface JarSignerRequest
- extends JavaToolRequest
-{
+public interface JarSignerRequest extends JavaToolRequest {
/**
* Gets the value of the {@code verbose} field.
@@ -133,84 +149,84 @@ public interface JarSignerRequest
*
* @param verbose the new value of the field {@code verbose}.
*/
- void setVerbose( boolean verbose );
+ void setVerbose(boolean verbose);
/**
* Sets the new given value to the field {@code keystore} of the request.
*
* @param keystore the new value of the field {@code keystore}.
*/
- void setKeystore( String keystore );
+ void setKeystore(String keystore);
/**
* Sets the new given value to the field {@code storetype} of the request.
*
* @param storetype the new value of the field {@code storetype}.
*/
- void setStoretype( String storetype );
+ void setStoretype(String storetype);
/**
* Sets the new given value to the field {@code storepass} of the request.
*
* @param storepass the new value of the field {@code storepass}.
*/
- void setStorepass( String storepass );
+ void setStorepass(String storepass);
/**
* Sets the new given value to the field {@code alias} of the request.
*
* @param alias the new value of the field {@code alias}.
*/
- void setAlias( String alias );
+ void setAlias(String alias);
/**
* Sets the new given value to the field {@code providerName} of the request.
*
* @param providerName the new value of the field {@code providerName}.
*/
- void setProviderName( String providerName );
+ void setProviderName(String providerName);
/**
* Sets the new given value to the field {@code providerClass} of the request.
*
* @param providerClass the new value of the field {@code providerClass}.
*/
- void setProviderClass( String providerClass );
+ void setProviderClass(String providerClass);
/**
* Sets the new given value to the field {@code providerArg} of the request.
*
* @param providerArg the new value of the field {@code providerArg}.
*/
- void setProviderArg( String providerArg );
+ void setProviderArg(String providerArg);
/**
* Sets the new given value to the field {@code maxMemory} of the request.
*
* @param maxMemory the new value of the field {@code maxMemory}.
*/
- void setMaxMemory( String maxMemory );
+ void setMaxMemory(String maxMemory);
/**
* Sets the new given value to the field {@code arguments} of the request.
*
* @param arguments the new value of the field {@code arguments}.
*/
- void setArguments( String... arguments );
+ void setArguments(String... arguments);
/**
* Sets the new given value to the field {@code workingDirectory} of the request.
*
* @param workingDirectory the new value of the field {@code workingDirectory}.
*/
- void setWorkingDirectory( File workingDirectory );
+ void setWorkingDirectory(File workingDirectory);
/**
* Sets the new given value to the field {@code archive} of the request.
*
* @param archive the new value of the field {@code archive}.
*/
- void setArchive( File archive );
+ void setArchive(File archive);
/**
* Sets the value of the command line tool parameter <pre>protected</pre>
@@ -218,6 +234,5 @@ public interface JarSignerRequest
* @param protectedAuthenticationPath iff the password must be given via a protected
* authentication path such as a dedicated PIN reader
*/
- void setProtectedAuthenticationPath( boolean protectedAuthenticationPath );
-
+ void setProtectedAuthenticationPath(boolean protectedAuthenticationPath);
}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
index 5064523..0af8d0e 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -27,9 +45,7 @@ import java.io.File;
* @author Tony Chemit
* @since 1.0
*/
-public class JarSignerSignRequest
- extends AbstractJarSignerRequest
-{
+public class JarSignerSignRequest extends AbstractJarSignerRequest {
/**
* See <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
@@ -58,70 +74,59 @@ public class JarSignerSignRequest
/**
* Location of the extra certchain file to be used during signing.
- *
+ *
* See <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
* @since 3.0.0
*/
protected File certchain;
- public String getKeypass()
- {
+ public String getKeypass() {
return keypass;
}
- public String getSigfile()
- {
+ public String getSigfile() {
return sigfile;
}
- public String getTsaLocation()
- {
+ public String getTsaLocation() {
return tsaLocation;
}
- public String getTsaAlias()
- {
+ public String getTsaAlias() {
return tsaAlias;
}
- public void setKeypass( String keypass )
- {
+ public void setKeypass(String keypass) {
this.keypass = keypass;
}
- public void setSigfile( String sigfile )
- {
+ public void setSigfile(String sigfile) {
this.sigfile = sigfile;
}
- public void setTsaLocation( String tsaLocation )
- {
+ public void setTsaLocation(String tsaLocation) {
this.tsaLocation = tsaLocation;
}
- public void setTsaAlias( String tsaAlias )
- {
+ public void setTsaAlias(String tsaAlias) {
this.tsaAlias = tsaAlias;
}
- public File getSignedjar()
- {
+ public File getSignedjar() {
return signedjar;
}
- public void setSignedjar( File signedjar )
- {
+ public void setSignedjar(File signedjar) {
this.signedjar = signedjar;
}
/**
* Sets certchain to be used.
- *
+ *
* @param certchain Cert Chain file path or {@code null} to remove the option
* @since 3.0.0
*/
- public void setCertchain( File certchain )
- {
+ public void setCertchain(File certchain) {
this.certchain = certchain;
}
@@ -129,8 +134,7 @@ public class JarSignerSignRequest
* Get certificate chain.
* @return Path to the certificate chain file or {@code null} if undefined
*/
- public File getCertchain()
- {
+ public File getCertchain() {
return certchain;
}
}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
index c0521d2..3b8cb49 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -19,9 +37,6 @@ package org.apache.maven.shared.jarsigner;
* under the License.
*/
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
-
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -35,17 +50,18 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
+import org.apache.maven.shared.utils.io.FileUtils;
+import org.apache.maven.shared.utils.io.IOUtil;
+
/**
* Useful methods.
*
* @author Tony Chemit
* @since 1.0
*/
-public class JarSignerUtil
-{
+public class JarSignerUtil {
- private JarSignerUtil()
- {
+ private JarSignerUtil() {
// static class
}
@@ -56,16 +72,12 @@ public class JarSignerUtil
* @param file The file to check, must not be <code>null</code>.
* @return <code>true</code> if the file looks like a ZIP file, <code>false</code> otherwise.
*/
- public static boolean isZipFile( final File file )
- {
+ public static boolean isZipFile(final File file) {
boolean result = false;
- try ( ZipInputStream zis = new ZipInputStream( new FileInputStream( file ) ) )
- {
+ try (ZipInputStream zis = new ZipInputStream(new FileInputStream(file))) {
result = zis.getNextEntry() != null;
- }
- catch ( Exception e )
- {
+ } catch (Exception e) {
// ignore, will fail below
}
@@ -79,44 +91,36 @@ public class JarSignerUtil
* @param jarFile The JAR file to unsign, must not be <code>null</code>.
* @throws IOException when error occurs during processing the file
*/
- public static void unsignArchive( File jarFile )
- throws IOException
- {
-
- File unsignedFile = new File( jarFile.getAbsolutePath() + ".unsigned" );
-
- try ( ZipInputStream zis = new ZipInputStream( new BufferedInputStream( new FileInputStream( jarFile ) ) );
- ZipOutputStream zos =
- new ZipOutputStream( new BufferedOutputStream( new FileOutputStream( unsignedFile ) ) ) )
- {
- for ( ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry() )
- {
- if ( isSignatureFile( ze.getName() ) )
- {
+ public static void unsignArchive(File jarFile) throws IOException {
+
+ File unsignedFile = new File(jarFile.getAbsolutePath() + ".unsigned");
+
+ try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(jarFile)));
+ ZipOutputStream zos =
+ new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(unsignedFile)))) {
+ for (ZipEntry ze = zis.getNextEntry(); ze != null; ze = zis.getNextEntry()) {
+ if (isSignatureFile(ze.getName())) {
continue;
}
- zos.putNextEntry( new ZipEntry( ze.getName() ) );
+ zos.putNextEntry(new ZipEntry(ze.getName()));
- if ( isManifestFile( ze.getName() ) )
- {
+ if (isManifestFile(ze.getName())) {
// build a new manifest while removing all digest entries
// see https://jira.codehaus.org/browse/MSHARED-314
- Manifest oldManifest = new Manifest( zis );
- Manifest newManifest = buildUnsignedManifest( oldManifest );
- newManifest.write( zos );
+ Manifest oldManifest = new Manifest(zis);
+ Manifest newManifest = buildUnsignedManifest(oldManifest);
+ newManifest.write(zos);
continue;
}
- IOUtil.copy( zis, zos );
+ IOUtil.copy(zis, zos);
}
-
}
- FileUtils.rename( unsignedFile, jarFile );
-
+ FileUtils.rename(unsignedFile, jarFile);
}
/**
@@ -129,30 +133,25 @@ public class JarSignerUtil
* @return the build manifest with no digest attributes
* @since 1.3
*/
- protected static Manifest buildUnsignedManifest( Manifest manifest )
- {
- Manifest result = new Manifest( manifest );
+ protected static Manifest buildUnsignedManifest(Manifest manifest) {
+ Manifest result = new Manifest(manifest);
result.getEntries().clear();
- for ( Map.Entry<String, Attributes> manifestEntry : manifest.getEntries().entrySet() )
- {
+ for (Map.Entry<String, Attributes> manifestEntry : manifest.getEntries().entrySet()) {
Attributes oldAttributes = manifestEntry.getValue();
Attributes newAttributes = new Attributes();
- for ( Map.Entry<Object, Object> attributesEntry : oldAttributes.entrySet() )
- {
- String attributeKey = String.valueOf( attributesEntry.getKey() );
- if ( !attributeKey.endsWith( "-Digest" ) )
- {
+ for (Map.Entry<Object, Object> attributesEntry : oldAttributes.entrySet()) {
+ String attributeKey = String.valueOf(attributesEntry.getKey());
+ if (!attributeKey.endsWith("-Digest")) {
// can add this attribute
- newAttributes.put( attributesEntry.getKey(), attributesEntry.getValue() );
+ newAttributes.put(attributesEntry.getKey(), attributesEntry.getValue());
}
}
- if ( !newAttributes.isEmpty() )
- {
+ if (!newAttributes.isEmpty()) {
// can add this entry
- result.getEntries().put( manifestEntry.getKey(), newAttributes );
+ result.getEntries().put(manifestEntry.getKey(), newAttributes);
}
}
@@ -167,22 +166,16 @@ public class JarSignerUtil
* archive does not contain any signature files.
* @throws IOException if scanning <code>jarFile</code> fails.
*/
- public static boolean isArchiveSigned( final File jarFile )
- throws IOException
- {
- if ( jarFile == null )
- {
- throw new NullPointerException( "jarFile" );
+ public static boolean isArchiveSigned(final File jarFile) throws IOException {
+ if (jarFile == null) {
+ throw new NullPointerException("jarFile");
}
- try ( ZipInputStream in = new ZipInputStream( new BufferedInputStream( new FileInputStream( jarFile ) ) ) )
- {
+ try (ZipInputStream in = new ZipInputStream(new BufferedInputStream(new FileInputStream(jarFile)))) {
boolean signed = false;
- for ( ZipEntry ze = in.getNextEntry(); ze != null; ze = in.getNextEntry() )
- {
- if ( isSignatureFile( ze.getName() ) )
- {
+ for (ZipEntry ze = in.getNextEntry(); ze != null; ze = in.getNextEntry()) {
+ if (isSignatureFile(ze.getName())) {
signed = true;
break;
}
@@ -200,37 +193,32 @@ public class JarSignerUtil
* @param entryName The name of the JAR file entry to check, must not be <code>null</code>.
* @return <code>true</code> if the entry is related to a signature, <code>false</code> otherwise.
*/
- protected static boolean isSignatureFile( String entryName )
- {
- if ( entryName.regionMatches( true, 0, "META-INF", 0, 8 ) )
- {
- entryName = entryName.replace( '\\', '/' );
-
- if ( entryName.indexOf( '/' ) == 8 && entryName.lastIndexOf( '/' ) == 8 )
- {
- return endsWithIgnoreCase( entryName, ".SF" ) || endsWithIgnoreCase( entryName, ".DSA" )
- || endsWithIgnoreCase( entryName, ".RSA" ) || endsWithIgnoreCase( entryName, ".EC" );
+ protected static boolean isSignatureFile(String entryName) {
+ if (entryName.regionMatches(true, 0, "META-INF", 0, 8)) {
+ entryName = entryName.replace('\\', '/');
+
+ if (entryName.indexOf('/') == 8 && entryName.lastIndexOf('/') == 8) {
+ return endsWithIgnoreCase(entryName, ".SF")
+ || endsWithIgnoreCase(entryName, ".DSA")
+ || endsWithIgnoreCase(entryName, ".RSA")
+ || endsWithIgnoreCase(entryName, ".EC");
}
}
return false;
}
- protected static boolean isManifestFile( String entryName )
- {
- if ( entryName.regionMatches( true, 0, "META-INF", 0, 8 ) )
- {
- entryName = entryName.replace( '\\', '/' );
+ protected static boolean isManifestFile(String entryName) {
+ if (entryName.regionMatches(true, 0, "META-INF", 0, 8)) {
+ entryName = entryName.replace('\\', '/');
- if ( entryName.indexOf( '/' ) == 8 && entryName.lastIndexOf( '/' ) == 8 )
- {
- return endsWithIgnoreCase( entryName, "/MANIFEST.MF" );
+ if (entryName.indexOf('/') == 8 && entryName.lastIndexOf('/') == 8) {
+ return endsWithIgnoreCase(entryName, "/MANIFEST.MF");
}
}
return false;
}
- private static boolean endsWithIgnoreCase( String str, String searchStr )
- {
- return str.regionMatches( true, str.length() - searchStr.length(), searchStr, 0, searchStr.length() );
+ private static boolean endsWithIgnoreCase(String str, String searchStr) {
+ return str.regionMatches(true, str.length() - searchStr.length(), searchStr, 0, searchStr.length());
}
}
diff --git a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
index 7e94288..9e601bf 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -25,21 +43,17 @@ package org.apache.maven.shared.jarsigner;
* @author Tony Chemit
* @since 1.0
*/
-public class JarSignerVerifyRequest
- extends AbstractJarSignerRequest
-{
+public class JarSignerVerifyRequest extends AbstractJarSignerRequest {
/**
* See <a href="http://docs.oracle.com/javase/6/docs/technotes/tools/windows/jarsigner.html#Options">options</a>.
*/
private boolean certs;
- public boolean isCerts()
- {
+ public boolean isCerts() {
return certs;
}
- public void setCerts( boolean certs )
- {
+ public void setCerts(boolean certs) {
this.certs = certs;
}
}
diff --git a/src/test/java/org/apache/maven/shared/jarsigner/AbstractJarSignerTest.java b/src/test/java/org/apache/maven/shared/jarsigner/AbstractJarSignerTest.java
index be7ac01..149951c 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/AbstractJarSignerTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/AbstractJarSignerTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -25,24 +43,18 @@ import java.io.IOException;
import org.apache.maven.shared.utils.io.FileUtils;
import org.codehaus.plexus.PlexusTestCase;
-public abstract class AbstractJarSignerTest
- extends PlexusTestCase
-{
+public abstract class AbstractJarSignerTest extends PlexusTestCase {
- protected File prepareTestJar( String filename )
- throws IOException
- {
- File file = new File( "src/test", filename );
- File target = new File( "target", filename );
+ protected File prepareTestJar(String filename) throws IOException {
+ File file = new File("src/test", filename);
+ File target = new File("target", filename);
- if ( target.exists() )
- {
- FileUtils.forceDelete( target );
+ if (target.exists()) {
+ FileUtils.forceDelete(target);
}
- FileUtils.copyFile( file, target );
+ FileUtils.copyFile(file, target);
return target;
}
-
}
diff --git a/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java b/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
index e6a84da..c2deae8 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -32,48 +50,41 @@ import java.util.jar.Manifest;
* @author Tony Chemit
* @since 1.1
*/
-public class JarSignerUtilTest
- extends AbstractJarSignerTest
-{
+public class JarSignerUtilTest extends AbstractJarSignerTest {
// Fix MSHARED-277
- public void testUnsignArchive()
- throws Exception
- {
+ public void testUnsignArchive() throws Exception {
- File target = prepareTestJar( "javax.persistence_2.0.5.v201212031355.jar" );
+ File target = prepareTestJar("javax.persistence_2.0.5.v201212031355.jar");
- assertTrue( JarSignerUtil.isArchiveSigned( target ) );
+ assertTrue(JarSignerUtil.isArchiveSigned(target));
// check that manifest contains some digest attributes
- Manifest originalManifest = readManifest( target );
- assertTrue( containsDigest( originalManifest ) );
+ Manifest originalManifest = readManifest(target);
+ assertTrue(containsDigest(originalManifest));
- Manifest originalCleanManifest = JarSignerUtil.buildUnsignedManifest( originalManifest );
- assertFalse( containsDigest( originalCleanManifest ) );
+ Manifest originalCleanManifest = JarSignerUtil.buildUnsignedManifest(originalManifest);
+ assertFalse(containsDigest(originalCleanManifest));
- assertTrue( originalCleanManifest.equals( JarSignerUtil.buildUnsignedManifest( originalCleanManifest ) ) );
+ assertTrue(originalCleanManifest.equals(JarSignerUtil.buildUnsignedManifest(originalCleanManifest)));
- JarSignerUtil.unsignArchive( target );
+ JarSignerUtil.unsignArchive(target);
- assertFalse( JarSignerUtil.isArchiveSigned( target ) );
+ assertFalse(JarSignerUtil.isArchiveSigned(target));
// check that manifest has no digest entry
// see https://jira.codehaus.org/browse/MSHARED-314
- Manifest manifest = readManifest( target );
-
- Manifest cleanManifest = JarSignerUtil.buildUnsignedManifest( manifest );
- assertFalse( containsDigest( cleanManifest ) );
+ Manifest manifest = readManifest(target);
- assertTrue( manifest.equals( cleanManifest ) );
- assertTrue( manifest.equals( originalCleanManifest ) );
+ Manifest cleanManifest = JarSignerUtil.buildUnsignedManifest(manifest);
+ assertFalse(containsDigest(cleanManifest));
+ assertTrue(manifest.equals(cleanManifest));
+ assertTrue(manifest.equals(originalCleanManifest));
}
- private Manifest readManifest( File file )
- throws IOException
- {
- JarFile jarFile = new JarFile( file );
+ private Manifest readManifest(File file) throws IOException {
+ JarFile jarFile = new JarFile(file);
Manifest manifest = jarFile.getManifest();
@@ -82,17 +93,13 @@ public class JarSignerUtilTest
return manifest;
}
- private boolean containsDigest( Manifest manifest )
- {
- for ( Map.Entry<String, Attributes> entry : manifest.getEntries().entrySet() )
- {
+ private boolean containsDigest(Manifest manifest) {
+ for (Map.Entry<String, Attributes> entry : manifest.getEntries().entrySet()) {
Attributes attr = entry.getValue();
- for ( Map.Entry<Object, Object> objectEntry : attr.entrySet() )
- {
- String attributeKey = String.valueOf( objectEntry.getKey() );
- if ( attributeKey.endsWith( "-Digest" ) )
- {
+ for (Map.Entry<Object, Object> objectEntry : attr.entrySet()) {
+ String attributeKey = String.valueOf(objectEntry.getKey());
+ if (attributeKey.endsWith("-Digest")) {
return true;
}
}
diff --git a/src/test/java/org/apache/maven/shared/jarsigner/SimpleJarSignTest.java b/src/test/java/org/apache/maven/shared/jarsigner/SimpleJarSignTest.java
index bb9dc6f..6d6b8ae 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/SimpleJarSignTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/SimpleJarSignTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
package org.apache.maven.shared.jarsigner;
/*
@@ -19,60 +37,52 @@ package org.apache.maven.shared.jarsigner;
* under the License.
*/
-import org.apache.maven.shared.utils.cli.javatool.JavaToolResult;
-
import java.io.File;
+import org.apache.maven.shared.utils.cli.javatool.JavaToolResult;
+
/**
* @author Olivier Lamy
*/
-public class SimpleJarSignTest
- extends AbstractJarSignerTest
-{
+public class SimpleJarSignTest extends AbstractJarSignerTest {
private JarSigner jarSigner;
- public void setUp()
- throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- jarSigner = (JarSigner) lookup( JarSigner.class.getName() );
+ jarSigner = (JarSigner) lookup(JarSigner.class.getName());
}
- public void testSimpleSign()
- throws Exception
- {
- File target = prepareTestJar( "simple.jar" );
+ public void testSimpleSign() throws Exception {
+ File target = prepareTestJar("simple.jar");
JarSignerSignRequest jarSignerRequest = new JarSignerSignRequest();
- jarSignerRequest.setArchive( target );
- jarSignerRequest.setKeystore( "src/test/keystore" );
- jarSignerRequest.setVerbose( true );
- jarSignerRequest.setAlias( "foo_alias" );
- jarSignerRequest.setKeypass( "key-passwd" );
- jarSignerRequest.setStorepass( "changeit" );
- jarSignerRequest.setSignedjar( new File( "target/ssimple.jar" ) );
+ jarSignerRequest.setArchive(target);
+ jarSignerRequest.setKeystore("src/test/keystore");
+ jarSignerRequest.setVerbose(true);
+ jarSignerRequest.setAlias("foo_alias");
+ jarSignerRequest.setKeypass("key-passwd");
+ jarSignerRequest.setStorepass("changeit");
+ jarSignerRequest.setSignedjar(new File("target/ssimple.jar"));
- JavaToolResult jarSignerResult = jarSigner.execute( jarSignerRequest );
+ JavaToolResult jarSignerResult = jarSigner.execute(jarSignerRequest);
- assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
+ assertEquals("not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode());
}
- public void testSimpleSignAndVerify()
- throws Exception
- {
+ public void testSimpleSignAndVerify() throws Exception {
testSimpleSign();
JarSignerVerifyRequest request = new JarSignerVerifyRequest();
- request.setCerts( true );
- request.setVerbose( true );
- request.setArchive( new File( "target/ssimple.jar" ) );
- request.setKeystore( "src/test/keystore" );
- request.setAlias( "foo_alias" );
- request.setStorepass( "changeit" );
+ request.setCerts(true);
+ request.setVerbose(true);
+ request.setArchive(new File("target/ssimple.jar"));
+ request.setKeystore("src/test/keystore");
+ request.setAlias("foo_alias");
+ request.setStorepass("changeit");
- JavaToolResult jarSignerResult = jarSigner.execute( request );
+ JavaToolResult jarSignerResult = jarSigner.execute(request);
- assertEquals( "not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode() );
+ assertEquals("not exit code 0 " + jarSignerResult.getExecutionException(), 0, jarSignerResult.getExitCode());
}
}