Skip to content

Commit

Permalink
Merge pull request shrinkwrap#163 from petrberan/SHRINKWRAP-533
Browse files Browse the repository at this point in the history
[SHRINKWRAP-533] Resolve code style issues
  • Loading branch information
petrberan authored Jul 16, 2024
2 parents 7ada26a + e4236f5 commit fde1e6f
Show file tree
Hide file tree
Showing 45 changed files with 106 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
* @author <a href="mailto:[email protected]">Tair Sabirgaliev</a>
*/
public enum ArchiveFormat {
UNKNOWN, ZIP, TAR, TAR_GZ, TAR_BZ;
UNKNOWN, ZIP, TAR, TAR_GZ, TAR_BZ
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private ClassLoaderSearchUtil() {
static Class<?> findClassFromClassLoaders(final String className, final Iterable<ClassLoader> classLoaders)
throws ClassNotFoundException, IllegalArgumentException {
// Precondition checks
assert className != null && className.length() > 0 : "Class Name must be specified";
assert className != null && !className.isEmpty() : "Class Name must be specified";
assert classLoaders != null : "ClassLoaders as search path must be specified";

// Find the class by searching through the CLs in order
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/jboss/shrinkwrap/api/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static Filter<ArchivePath> createRegExpFilter(String regExpFilterImplNam
private static Filter<ArchivePath> getFilterInstance(final String filterClassName, final Class<?>[] ctorTypes,
final Object[] ctorArguments) {
// Precondition checks
assert filterClassName != null && filterClassName.length() > 0 : "Filter class name must be specified";
assert filterClassName != null && !filterClassName.isEmpty() : "Filter class name must be specified";
assert ctorTypes != null : "Construction types must be specified";
assert ctorArguments != null : "Construction arguments must be specified";
assert ctorTypes.length == ctorArguments.length : "The number of ctor arguments and their types must match";
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/org/jboss/shrinkwrap/api/ShrinkWrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static <T extends Assignable> T create(final Class<T> type, final String
if (type == null) {
throw new IllegalArgumentException("Type must be specified");
}
if (archiveName == null || archiveName.length() == 0) {
if (archiveName == null || archiveName.isEmpty()) {
throw new IllegalArgumentException("ArchiveName must be specified");
}

Expand Down Expand Up @@ -201,7 +201,7 @@ private enum DefaultDomainWrapper {
/**
* The wrapped default domain
*/
private transient Domain domain = ShrinkWrap.createDomain();
private final transient Domain domain = ShrinkWrap.createDomain();

/**
* Obtains the default domain for the system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ClassAsset implements Asset {
*/
private static final String EXTENSION_CLASS = ".class";

private Class<?> clazz;
private final Class<?> clazz;

/**
* Load any class as a resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* @author <a href="mailto:[email protected]">Aslak Knutsen</a>
*/
public class ClassLoaderAsset implements Asset {
private String resourceName;
private final String resourceName;

private ClassLoader classLoader;
private final ClassLoader classLoader;

/**
* Load a named resource using the current threads context classloader.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author <a href="mailto:[email protected]">Aslak Knutsen</a>
*/
public class FileAsset implements Asset {
private File file;
private final File file;

/**
* Load the specified File.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ private Node node(final Archive<?> archive, final ArchivePath path) throws FileN
return node;
}
// SHRINKWRAP-308 We've asked for a path that doesn't exist
throw new FileNotFoundException("Requested path: " + path + " does not exist in "
+ archive.toString());
throw new FileNotFoundException("Requested path: " + path + " does not exist in " + archive);
}

private ArchivePath convertToArchivePath(URL url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
* ApiTestUtils
Expand Down Expand Up @@ -46,7 +47,7 @@ static String convertToString(InputStream in) throws Exception {
}
out.close();
in.close();
return new String(out.toByteArray(), "UTF-8");
return new String(out.toByteArray(), StandardCharsets.UTF_8);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

import org.jboss.shrinkwrap.api.nio2.file.SeekableInMemoryByteChannelTestCase;
Expand All @@ -43,8 +43,6 @@ public class MemoryAssetTestCase {

private static final String CONTENTS_BUFFER = "Andrew Lee Rubinger";

private static final String UTF8 = "UTF-8";

/**
* Instance under test
*/
Expand All @@ -55,11 +53,7 @@ public class MemoryAssetTestCase {
@Before
public void init() {
this.asset = new MemoryAsset();
try {
buffer = ByteBuffer.wrap(CONTENTS_BUFFER.getBytes(UTF8));
} catch (final UnsupportedEncodingException uee) {
throw new RuntimeException(uee);
}
buffer = ByteBuffer.wrap(CONTENTS_BUFFER.getBytes(StandardCharsets.UTF_8));
}

@After
Expand All @@ -84,7 +78,7 @@ public void read() throws IOException {
Assert.assertEquals("Setting position should return the asset", this.asset, channel);
final int numBytesRead = channel.read(ByteBuffer.wrap(contents));
final String expected = "dr";
final String contentsRead = new String(contents, UTF8);
final String contentsRead = new String(contents, StandardCharsets.UTF_8);
Assert.assertEquals("Read should report correct number of bytes read", contents.length, numBytesRead);
Assert.assertEquals("Channel should respect explicit position during reads", expected, contentsRead);
}
Expand All @@ -102,12 +96,12 @@ public void openStream() throws IOException {
public void write() throws IOException {
this.asset.write(buffer);
final int newPosition = 2;
final int numBytesWritten = this.asset.position(newPosition).write(ByteBuffer.wrap("DR".getBytes(UTF8)));
final int numBytesWritten = this.asset.position(newPosition).write(ByteBuffer.wrap("DR".getBytes(StandardCharsets.UTF_8)));
// Read 3 bytes from the new position
final byte[] contents = new byte[3];
this.asset.position(newPosition).read(ByteBuffer.wrap(contents));
final String expected = "DRe";
final String read = new String(contents, UTF8);
final String read = new String(contents, StandardCharsets.UTF_8);
Assert.assertEquals("Write should report correct number of bytes written", 2, numBytesWritten);
Assert.assertEquals("Channel should respect explicit position during writes", expected, read);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.StandardCharsets;
import java.util.logging.Logger;

import org.jboss.shrinkwrap.api.nio2.file.SeekableInMemoryByteChannel;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -43,8 +42,6 @@ public class SeekableInMemoryByteChannelTestCase {
private static final String CONTENTS_SMALLER_BUFFER = "Andrew Lee Rubinger";
private static final String CONTENTS_BIGGER_BUFFER = "Andrew Lee Rubinger, JBoss by Red Hat";

private static final String UTF8 = "UTF-8";

/**
* Instance under test
*/
Expand All @@ -56,12 +53,8 @@ public class SeekableInMemoryByteChannelTestCase {
@Before
public void init() {
this.channel = new SeekableInMemoryByteChannel();
try {
smallerBuffer = ByteBuffer.wrap(CONTENTS_SMALLER_BUFFER.getBytes(UTF8));
biggerBuffer = ByteBuffer.wrap(CONTENTS_BIGGER_BUFFER.getBytes(UTF8));
} catch (final UnsupportedEncodingException uee) {
throw new RuntimeException(uee);
}
smallerBuffer = ByteBuffer.wrap(CONTENTS_SMALLER_BUFFER.getBytes(StandardCharsets.UTF_8));
biggerBuffer = ByteBuffer.wrap(CONTENTS_BIGGER_BUFFER.getBytes(StandardCharsets.UTF_8));
}

@After
Expand Down Expand Up @@ -122,7 +115,7 @@ public void read() throws IOException {
// Read 2 bytes from the new position
final int numBytesRead = this.channel.position(newPosition).read(ByteBuffer.wrap(contents));
final String expected = "dr";
final String contentsRead = new String(contents, UTF8);
final String contentsRead = new String(contents, StandardCharsets.UTF_8);
Assert.assertEquals("Read should report correct number of bytes read", contents.length, numBytesRead);
Assert.assertEquals("Channel should respect explicit position during reads", expected, contentsRead);
}
Expand Down Expand Up @@ -160,12 +153,12 @@ public void nothingToRead() throws IOException {
public void write() throws IOException {
this.channel.write(smallerBuffer);
final int newPosition = 2;
final int numBytesWritten = this.channel.position(newPosition).write(ByteBuffer.wrap("DR".getBytes(UTF8)));
final int numBytesWritten = this.channel.position(newPosition).write(ByteBuffer.wrap("DR".getBytes(StandardCharsets.UTF_8)));
// Read 3 bytes from the new position
final byte[] contents = new byte[3];
this.channel.position(newPosition).read(ByteBuffer.wrap(contents));
final String expected = "DRe";
final String read = new String(contents, UTF8);
final String read = new String(contents, StandardCharsets.UTF_8);
Assert.assertEquals("Write should report correct number of bytes written", 2, numBytesWritten);
Assert.assertEquals("Channel should respect explicit position during writes", expected, read);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public abstract class MemoryMapArchiveBase<T extends Archive<T>> extends Archive
* If the configuration is not specified
*/
public MemoryMapArchiveBase(final Configuration configuration) throws IllegalArgumentException {
this("Archive-" + UUID.randomUUID().toString() + ".jar", configuration);
this("Archive-" + UUID.randomUUID() + ".jar", configuration);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ public class NodeImpl implements Node {
/**
* The path of this node inside the {@link Archive}
*/
private ArchivePath path;
private final ArchivePath path;

/**
* The asset this node holds.
*/
private Asset asset;
private final Asset asset;

/**
* The children nodes.
*/
private Set<Node> children = Collections.synchronizedSet(new LinkedHashSet<>());
private final Set<Node> children = Collections.synchronizedSet(new LinkedHashSet<>());

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class ServiceExtensionLoader implements ExtensionLoader {
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

private Map<Class<?>, Class<?>> cache = new HashMap<>();
private Map<Class<?>, ExtensionWrapper> extensionMappings = new HashMap<>();
private final Map<Class<?>, Class<?>> cache = new HashMap<>();
private final Map<Class<?>, ExtensionWrapper> extensionMappings = new HashMap<>();

/**
* ClassLoader used for loading extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class URLPackageScanner {


// private final Set<String> classes = new HashSet<String>();
private Callback callback;
private final Callback callback;

/**
* Factory method to create an instance of URLPackageScanner.
Expand Down Expand Up @@ -151,7 +151,7 @@ private void handle(Set<String> paths) throws IOException, ClassNotFoundExceptio
private void handle(File file, String packageName) {
for (File child : file.listFiles()) {
if (!child.isDirectory() && child.getName().endsWith(SUFFIX_CLASS)) {
final String packagePrefix = packageName.length() > 0 ? packageName + "." : packageName;
final String packagePrefix = !packageName.isEmpty() ? packageName + "." : packageName;
String className = packagePrefix + child.getName().substring(0, child.getName().lastIndexOf(SUFFIX_CLASS));
foundClass(className, prefix + className.replace('.', '/') + SUFFIX_CLASS);
} else if (child.isDirectory() && addRecursively) {
Expand All @@ -167,7 +167,7 @@ private void foundClass(String className, String path) {
private List<URL> loadResources(String name) throws IOException {
ArrayList<URL> resources = Collections.list(classLoader.getResources(prefix + name));

if (resources.size() == 0) {
if (resources.isEmpty()) {
prefix = WEB_INF_CLASSES_DIR;
resources = Collections.list(classLoader.getResources(prefix + name));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void notNull(final Object obj, final String message) throws Illega
* Thrown if obj is null
*/
public static void notNullOrEmpty(final String string, final String message) throws IllegalArgumentException {
if (string == null || string.length() == 0) {
if (string == null || string.isEmpty()) {
throw new IllegalArgumentException(message);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1377,13 +1377,13 @@ public boolean include(ArchivePath path) {
ArchivePath classArchivePath = AssetUtil.getFullPathForClassResource(clazz);
String expression = classArchivePath.get().replace(".class", "\\$.*");
return path.get().matches(expression);
};
}
}, adjustedCl,
// Assumes a null package is a class in the default package
clazz.getPackage() == null ? DEFAULT_PACKAGE_NAME : clazz.getPackage().getName());
}
return covarientReturn();
};
}

/*
* (non-Javadoc)
Expand Down Expand Up @@ -1725,7 +1725,7 @@ public T addAsLibrary(final Archive<?> archive) throws IllegalArgumentException
Validate.notNull(archive, "Archive must be specified");
// Libraries are JARs, so add as ZIP
return add(archive, getLibraryPath(), ZipExporter.class);
};
}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
class ZipExporterDelegate extends AbstractExporterDelegate<InputStream> {

private boolean compressed;
private final boolean compressed;

protected ZipExporterDelegate(final Archive<?> archive) {
super(archive);
Expand All @@ -43,7 +43,7 @@ protected ZipExporterDelegate(final Archive<?> archive) {
if (archive.getContent().isEmpty()) {
throw new IllegalArgumentException(
"[SHRINKWRAP-93] Cannot use this JDK-based implementation to export as ZIP an archive with no content: "
+ archive.toString());
+ archive);
}
}

Expand All @@ -55,7 +55,7 @@ protected ZipExporterDelegate(final Archive<?> archive, final boolean compressed
if (archive.getContent().isEmpty()) {
throw new IllegalArgumentException(
"[SHRINKWRAP-93] Cannot use this JDK-based implementation to export as ZIP an archive with no content: "
+ archive.toString());
+ archive);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
class ZipOnDemandInputStream extends AbstractOnDemandInputStream<ZipOutputStream> {


private boolean compressed;
private static long SYSTIME = System.currentTimeMillis();
private final boolean compressed;
private static final long SYSTIME = System.currentTimeMillis();

/**
* Creates stream directly from archive with compression.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExcludePaths implements Filter<ArchivePath> {
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

private Set<String> paths;
private final Set<String> paths;

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ExcludeRegExpPaths implements Filter<ArchivePath> {
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

private String expression;
private final String expression;

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class IncludePaths implements Filter<ArchivePath> {
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

private Set<String> paths;
private final Set<String> paths;

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class IncludeRegExpPaths implements Filter<ArchivePath> {
// Instance Members -------------------------------------------------------------------||
// -------------------------------------------------------------------------------------||

private String expression;
private final String expression;

// -------------------------------------------------------------------------------------||
// Constructor ------------------------------------------------------------------------||
Expand Down
Loading

0 comments on commit fde1e6f

Please sign in to comment.