You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2023/05/24 16:26:15 UTC
[maven-jarsigner] 02/02: [MSHARED-1258] Reformat code
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MSHARED-1258
in repository https://gitbox.apache.org/repos/asf/maven-jarsigner.git
commit e3448ec750e172c672f87da8e483ed6c4c9c1428
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Wed May 24 17:56:59 2023 +0200
[MSHARED-1258] Reformat code
---
pom.xml | 4 +-
.../shared/jarsigner/AbstractJarSignerRequest.java | 92 ++++------
.../CommandLineConfigurationException.java | 21 +--
.../maven/shared/jarsigner/DefaultJarSigner.java | 72 +++-----
.../apache/maven/shared/jarsigner/JarSigner.java | 11 +-
.../jarsigner/JarSignerCommandLineBuilder.java | 194 +++++++++------------
.../maven/shared/jarsigner/JarSignerRequest.java | 40 ++---
.../shared/jarsigner/JarSignerSignRequest.java | 49 ++----
.../maven/shared/jarsigner/JarSignerUtil.java | 145 ++++++---------
.../shared/jarsigner/JarSignerVerifyRequest.java | 15 +-
.../shared/jarsigner/AbstractJarSignerTest.java | 25 +--
.../maven/shared/jarsigner/JarSignerUtilTest.java | 62 +++----
.../maven/shared/jarsigner/SimpleJarSignTest.java | 61 +++----
13 files changed, 304 insertions(+), 487 deletions(-)
diff --git a/pom.xml b/pom.xml
index e9cd41f..82ac714 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
@@ -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>
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..8e2e5d5 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/AbstractJarSignerRequest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,21 +16,19 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.utils.cli.javatool.AbstractJavaToolRequest;
+package org.apache.maven.shared.jarsigner;
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 +98,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..5aa5322 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/CommandLineConfigurationException.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
/**
* Signals an error during the construction of the command line used to invoke jar signer.
@@ -25,9 +24,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 +34,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 +43,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..b21e487 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/DefaultJarSigner.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
import org.apache.maven.shared.utils.cli.Commandline;
import org.apache.maven.shared.utils.cli.StreamConsumer;
@@ -31,73 +30,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..a78c9e8 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSigner.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
import org.apache.maven.shared.utils.cli.javatool.JavaTool;
@@ -27,8 +26,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 fb2b5d4..fdca271 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,10 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
+
+import java.io.File;
+import java.io.IOException;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Arg;
@@ -25,208 +27,170 @@ 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 ( !( keystore == null || keystore.isEmpty() ) )
- {
- cli.createArg().setValue( "-keystore" );
- cli.createArg().setValue( keystore );
+ if (!(keystore == null || keystore.isEmpty())) {
+ cli.createArg().setValue("-keystore");
+ cli.createArg().setValue(keystore);
}
String storepass = request.getStorepass();
- if ( !( storepass == null || storepass.isEmpty() ) )
- {
- cli.createArg().setValue( "-storepass" );
+ if (!(storepass == null || storepass.isEmpty())) {
+ 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 ( !( storetype == null || storetype.isEmpty() ) )
- {
- cli.createArg().setValue( "-storetype" );
- cli.createArg().setValue( storetype );
+ if (!(storetype == null || storetype.isEmpty())) {
+ cli.createArg().setValue("-storetype");
+ cli.createArg().setValue(storetype);
}
String providerName = request.getProviderName();
- if ( !( providerName == null || providerName.isEmpty() ) )
- {
- cli.createArg().setValue( "-providerName" );
- cli.createArg().setValue( providerName );
+ if (!(providerName == null || providerName.isEmpty())) {
+ cli.createArg().setValue("-providerName");
+ cli.createArg().setValue(providerName);
}
String providerClass = request.getProviderClass();
- if ( !( providerClass == null || providerClass.isEmpty() ) )
- {
- cli.createArg().setValue( "-providerClass" );
- cli.createArg().setValue( providerClass );
+ if (!(providerClass == null || providerClass.isEmpty())) {
+ cli.createArg().setValue("-providerClass");
+ cli.createArg().setValue(providerClass);
}
String providerArg = request.getProviderArg();
- if ( !( providerArg == null || providerArg.isEmpty() ) )
- {
- cli.createArg().setValue( "-providerArg" );
- cli.createArg().setValue( providerArg );
+ if (!(providerArg == null || providerArg.isEmpty())) {
+ 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 ( maxMemory != null && !maxMemory.isEmpty() )
- {
- cli.createArg().setValue( "-J-Xmx" + maxMemory );
+ if (maxMemory != null && !maxMemory.isEmpty()) {
+ 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 ( !( alias == null || alias.isEmpty() ) )
- {
- cli.createArg().setValue( alias );
+ if (!(alias == null || alias.isEmpty())) {
+ 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 ( !( keypass == null || keypass.isEmpty() ) )
- {
- cli.createArg().setValue( "-keypass" );
+ if (!(keypass == null || keypass.isEmpty())) {
+ 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 ( !( sigfile == null || sigfile.isEmpty() ) )
- {
- cli.createArg().setValue( "-sigfile" );
- cli.createArg().setValue( sigfile );
+ if (!(sigfile == null || sigfile.isEmpty())) {
+ 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..1b7d086 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerRequest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,20 +16,19 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.utils.cli.javatool.JavaToolRequest;
+package org.apache.maven.shared.jarsigner;
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 +130,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 +215,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..c368138 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerSignRequest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
import java.io.File;
@@ -27,9 +26,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 +55,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 +115,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..db68d4c 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerUtil.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,9 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.utils.io.FileUtils;
-import org.apache.maven.shared.utils.io.IOUtil;
+package org.apache.maven.shared.jarsigner;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -35,17 +31,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 +53,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 +72,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 +114,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 +147,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 +174,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..34c4f4e 100644
--- a/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
+++ b/src/main/java/org/apache/maven/shared/jarsigner/JarSignerVerifyRequest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
/**
* Specifies the parameters used to control a jar signer verify operation invocation.
@@ -25,21 +24,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..c8032a9 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/AbstractJarSignerTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/AbstractJarSignerTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
import java.io.File;
import java.io.IOException;
@@ -25,24 +24,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..2004c46 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/JarSignerUtilTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -9,7 +7,7 @@ package org.apache.maven.shared.jarsigner;
* "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
+ * 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
@@ -18,6 +16,7 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.jarsigner;
import java.io.File;
import java.io.IOException;
@@ -32,48 +31,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 +74,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..122837d 100644
--- a/src/test/java/org/apache/maven/shared/jarsigner/SimpleJarSignTest.java
+++ b/src/test/java/org/apache/maven/shared/jarsigner/SimpleJarSignTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.jarsigner;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,61 +16,54 @@ package org.apache.maven.shared.jarsigner;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.utils.cli.javatool.JavaToolResult;
+package org.apache.maven.shared.jarsigner;
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());
}
}