Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fuinorg/utils4j
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.9.2
Choose a base ref
...
head repository: fuinorg/utils4j
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.10.0
Choose a head ref

Commits on Oct 9, 2016

  1. Copy the full SHA
    2b9b3c9 View commit details

Commits on Dec 23, 2016

  1. Started new iteration

    michael-schnell committed Dec 23, 2016
    Copy the full SHA
    be106f2 View commit details
  2. Added JavaDoc badge

    michael-schnell committed Dec 23, 2016
    Copy the full SHA
    400f289 View commit details

Commits on Dec 24, 2016

  1. Added sigtest plugin

    michael-schnell committed Dec 24, 2016
    Copy the full SHA
    a3aeb8e View commit details

Commits on Aug 20, 2017

  1. Copy the full SHA
    540e9ba View commit details
  2. Fixed JavaDoc

    michael-schnell committed Aug 20, 2017
    Copy the full SHA
    b96cf91 View commit details

Commits on Sep 21, 2017

  1. Copy the full SHA
    f92de3f View commit details

Commits on Oct 14, 2017

  1. Copy the full SHA
    9362336 View commit details
  2. Fixed links

    michael-schnell committed Oct 14, 2017
    Copy the full SHA
    26760b0 View commit details
  3. Added headings

    michael-schnell committed Oct 14, 2017
    Copy the full SHA
    3a25e30 View commit details
  4. Added CDATA example

    michael-schnell committed Oct 14, 2017
    Copy the full SHA
    19a9ba3 View commit details
  5. Added text

    michael-schnell committed Oct 14, 2017
    Copy the full SHA
    e75afdb View commit details
  6. Enhanced example

    michael-schnell committed Oct 14, 2017
    Copy the full SHA
    6ec1a65 View commit details
  7. Copy the full SHA
    d8ed46f View commit details

Commits on Feb 24, 2018

  1. Copy the full SHA
    559125d View commit details
  2. Removed unstable test

    michael-schnell committed Feb 24, 2018
    Copy the full SHA
    c216792 View commit details
  3. Copy the full SHA
    d6ea642 View commit details

Commits on Mar 17, 2018

  1. Just to trigger build

    michael-schnell committed Mar 17, 2018
    Copy the full SHA
    246e2dc View commit details

Commits on Apr 14, 2018

  1. Added doc

    michael-schnell committed Apr 14, 2018
    Copy the full SHA
    0223598 View commit details

Commits on Apr 30, 2018

  1. Copy the full SHA
    ad72ecd View commit details

Commits on May 1, 2018

  1. Copy the full SHA
    e7cb0bb View commit details
  2. Copy the full SHA
    859dd71 View commit details
  3. Copy the full SHA
    15e0f6f View commit details
  4. Copy the full SHA
    bc229ca View commit details
  5. Switched to JaCoco

    michael-schnell committed May 1, 2018
    Copy the full SHA
    10e74bd View commit details
  6. Copy the full SHA
    ec00039 View commit details
  7. Added new method

    michael-schnell committed May 1, 2018
    Copy the full SHA
    f1c2693 View commit details
  8. Added Jandex Utils

    michael-schnell committed May 1, 2018
    Copy the full SHA
    635b8db View commit details

Commits on May 19, 2018

  1. Need to add persistent Eclipse checkstyle config.

    m2e-code-quality-plugin does not handle report section plugin.
    See m2e-code-quality/m2e-code-quality#118
    michael-schnell committed May 19, 2018
    Copy the full SHA
    1016963 View commit details
  2. Copy the full SHA
    5ba77c4 View commit details
  3. Release 0.10.0

    michael-schnell committed May 19, 2018
    Copy the full SHA
    add4368 View commit details
Showing with 2,528 additions and 549 deletions.
  1. +11 −0 .checkstyle
  2. +1 −0 .gitignore
  3. +0 −16 META-INF/MANIFEST.MF
  4. +174 −10 README.md
  5. +118 −116 pom.xml
  6. +44 −0 src/main/java/org/fuin/utils4j/CDataXmlAdapter.java
  7. +61 −0 src/main/java/org/fuin/utils4j/CDataXmlStreamWriter.java
  8. +162 −0 src/main/java/org/fuin/utils4j/JandexUtils.java
  9. +88 −4 src/main/java/org/fuin/utils4j/JaxbUtils.java
  10. +196 −0 src/main/java/org/fuin/utils4j/PropertiesUtils.java
  11. +284 −250 src/main/java/org/fuin/utils4j/Utils4J.java
  12. +116 −0 src/main/java/org/fuin/utils4j/WaitHelper.java
  13. +211 −0 src/main/java/org/fuin/utils4j/XMLStreamWriterAdapter.java
  14. +73 −0 src/test/java/org/fuin/utils4j/CDataJaxbTest.java
  15. +1 −1 src/test/java/org/fuin/utils4j/CancelableVolatileTest.java
  16. +1 −1 src/test/java/org/fuin/utils4j/ChangeTrackingMapTest.java
  17. +1 −1 src/test/java/org/fuin/utils4j/ChangeTrackingUniqueListTest.java
  18. +1 −1 src/test/java/org/fuin/utils4j/ClasspathURLStreamHandlerTest.java
  19. +1 −1 src/test/java/org/fuin/utils4j/IllegalNullArgumentExceptionTest.java
  20. +1 −1 src/test/java/org/fuin/utils4j/InvokeMethodFailedExceptionTest.java
  21. +124 −0 src/test/java/org/fuin/utils4j/JandexUtilsTest.java
  22. +1 −1 src/test/java/org/fuin/utils4j/LockingFailedExceptionTest.java
  23. +48 −0 src/test/java/org/fuin/utils4j/MyClassWithCData.java
  24. +1 −1 src/test/java/org/fuin/utils4j/PropertiesFilePreferencesTest.java
  25. +1 −1 src/test/java/org/fuin/utils4j/PropertiesFileTest.java
  26. +161 −0 src/test/java/org/fuin/utils4j/PropertiesUtilsTest.java
  27. +4 −8 src/test/java/org/fuin/utils4j/PropertyTest.java
  28. +1 −1 src/test/java/org/fuin/utils4j/RandomAccessFileInputStreamTest.java
  29. +10 −3 src/test/java/org/fuin/utils4j/RandomAccessFileOutputStreamTest.java
  30. +4 −4 src/test/java/org/fuin/utils4j/TestHelper.java
  31. +216 −110 src/test/java/org/fuin/utils4j/Utils4JTest.java
  32. +1 −1 src/test/java/org/fuin/utils4j/VariableResolverTest.java
  33. +136 −0 src/test/java/org/fuin/utils4j/WaitHelperTest.java
  34. +74 −0 src/test/java/org/fuin/utils4j/examples/CDataJaxbExample.java
  35. +66 −0 src/test/java/org/fuin/utils4j/examples/FindJarsAndClassesInClasspath.java
  36. +118 −0 src/test/java/org/fuin/utils4j/examples/WaitHelperExample.java
  37. +1 −1 src/test/java/org/fuin/utils4j/fileprocessor/FileHandlerResultTest.java
  38. +1 −1 src/test/java/org/fuin/utils4j/fileprocessor/FileOrderTest.java
  39. +1 −1 src/test/java/org/fuin/utils4j/fileprocessor/FileProcessorTest.java
  40. +1 −1 src/test/java/org/fuin/utils4j/filter/AndFilterTest.java
  41. +1 −1 src/test/java/org/fuin/utils4j/filter/BooleanFilterTest.java
  42. +1 −1 src/test/java/org/fuin/utils4j/filter/BooleanPropertyFilterTest.java
  43. +1 −1 src/test/java/org/fuin/utils4j/filter/IntegerFilterTest.java
  44. +1 −1 src/test/java/org/fuin/utils4j/filter/IntegerPropertyFilterTest.java
  45. +1 −1 src/test/java/org/fuin/utils4j/filter/ListFilterTest.java
  46. +1 −1 src/test/java/org/fuin/utils4j/filter/OrFilterTest.java
  47. +1 −1 src/test/java/org/fuin/utils4j/filter/PropertyFilterTest.java
  48. +1 −1 src/test/java/org/fuin/utils4j/filter/RegExprFilterTest.java
  49. +1 −1 src/test/java/org/fuin/utils4j/filter/RegExprPropertyFilterTest.java
  50. +1 −1 src/test/java/org/fuin/utils4j/filter/StringFilterTest.java
  51. +1 −1 src/test/java/org/fuin/utils4j/filter/StringPropertyFilterTest.java
  52. +1 −1 src/test/java/org/fuin/utils4j/filter/TokenFilterTest.java
  53. +1 −1 src/test/java/org/fuin/utils4j/filter/TokenPropertyFilterTest.java
  54. BIN src/test/resources/ext4logback-0.2.0.jar
11 changes: 11 additions & 0 deletions .checkstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="true">
<local-check-config name="maven-checkstyle-plugin default" location="http://www.fuin.org/files/checkstyle-2018-05-01.xml" type="remote" description="maven-checkstyle-plugin configuration default">
<property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/>
</local-check-config>
<fileset name="java-sources-default" enabled="true" check-config-name="maven-checkstyle-plugin default" local="true">
<file-match-pattern match-pattern="^src/main/resources.*\.properties" exclude-pattern="true"/>
<file-match-pattern match-pattern="^src/test/resources/.*\.properties" exclude-pattern="true"/>
</fileset>
</fileset-config>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.*
!.gitignore
!.gitkeep
!.checkstyle
target
META-INF
*.log
16 changes: 0 additions & 16 deletions META-INF/MANIFEST.MF

This file was deleted.

184 changes: 174 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ A small Java library that contains several helpful utility classes.
[![Build Status](https://fuin-org.ci.cloudbees.com/job/utils4j/badge/icon)](https://fuin-org.ci.cloudbees.com/job/utils4j/)
[![Coverage Status](https://coveralls.io/repos/fuinorg/utils4j/badge.svg?branch=master)](https://coveralls.io/r/fuinorg/utils4j?branch=master)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.fuin/utils4j/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.fuin/utils4j/)
[![Javadocs](https://www.javadoc.io/badge/org.fuin/utils4j.svg)](https://www.javadoc.io/doc/org.fuin/utils4j)
[![LGPLv3 License](http://img.shields.io/badge/license-LGPLv3-blue.svg)](https://www.gnu.org/licenses/lgpl.html)
[![Java Development Kit 1.8](https://img.shields.io/badge/JDK-1.8-green.svg)](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

@@ -15,15 +16,31 @@ A small Java library that contains several helpful utility classes.

* * *

##Features
# Features

###URL support for "classpath:" scheme
* [URL support for "classpath:" scheme](#url-support-for-classpath-scheme)
* [Variable resolver](#variable-resolver)
* [ZIP and UNZIP](#zip-and-unzip)
* [Tracking changes of a list / map](##tracking-changes-of-a-list--map)
* [Easy file locking](#easy-file-locking)
* [Properties file preferences](#properties-file-preferences)
* [JAXB CDATA Stream Writer](#jaxb-cdata-stream-writer)
* [Wait for code to finish](#wait-for-code-to-finish)
* [Find all JARs and classes in the classpath](#find-all-jars-and-classes-in-the-classpath)
* [Analyze classes in the classpath with Jandex](#analyze-classes-in-the-classpath-with-jandex)

* * *

# Description

### URL support for "classpath:" scheme
```Java
URL url = Utils4J.url("classpath:org/fuin/utils4j/test.properties");
```
A full example can be found here: [ClasspathURLExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ClasspathURLExample.java)

###Variable resolver

### Variable resolver
Resolves variable references in a map and prevents on cycles.
```
a=1
@@ -38,7 +55,8 @@ c=1/2/3
```
A full example can be found here: [VariableResolverExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/VariableResolverExample.java)

###ZIP and UNZIP

### ZIP and UNZIP
Compress and descompress a complete directory and it's subdirectories with a single line of code
```Java
final File zipDir = new File(Utils4J.getTempDir(), "mydir");
@@ -48,7 +66,8 @@ Utils4J.unzip(zipFile, Utils4J.getTempDir());
```
A full example can be found here: [ZipDirExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ZipDirExample.java)

###Tracking changes of a list / map

### Tracking changes of a list / map
This is a wrapper for lists that keeps track of all changes made to the list. This means adding, replacing or deleting elements is tracked - not the changes to the objects itself. It's also possible to revert (undo) all changes made to the list. A restriction is that no duplicate elements are allowed in the list.
```Java
List<String> list = new ArrayList<>();
@@ -61,7 +80,9 @@ trackingList.revert();
A list example can be found here: [ChangeTrackingUniqueListExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ChangeTrackingUniqueListExample.java)
A map example can be found here: [ChangeTrackingMapExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/ChangeTrackingMapExample.java)

###Easy file locking

### Easy file locking
Allows to synchronize local processes by using a file based lock.
```Java
FileLock lock = Utils4J.lockRandomAccessFile(randomAccessFile, tryLockMax, tryWaitMillis);
try {
@@ -72,17 +93,162 @@ try {
```
A full example can be found here: [LockFileExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/LockFileExample.java)

###Properties file preferences

### Properties file preferences
Shows the use of a directory and properties file based [Preferences API](http://docs.oracle.com/javase/7/docs/technotes/guides/preferences/) implementation. It's basically a replacement for the registry based implementation on Windows.
```Java
System.setProperty("java.util.prefs.PreferencesFactory", PropertiesFilePreferencesFactory.class.getName());
Preferences userPrefs = Preferences.userRoot();
```
A full example can be found here: [PropertiesFilePreferencesFactoryExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/PropertiesFilePreferencesFactoryExample.java)


### JAXB CDATA Stream Writer

XML stream writer that does **not** escape the content of a CDATA section.
This is meant to be used with JAXB to serialize a string field to a CDATA section.
The field to write as CDATA section is annotated with a CDataXmlAdapter.

Example of class using the adapter:
```Java
/**
* Example class with CDATA field.
*/
@XmlRootElement(name = "my-class-with-cdata")
public final class MyClassWithCData {

// Field has the CDataXmlAdapter
@XmlValue
@XmlJavaTypeAdapter(CDataXmlAdapter.class)
private String content;

}
```
If you just need to unmarshal a CDATA section, using the above annotation is all you need to do.

If you need to marshal a class with CDATA content you need to use the CDataXmlStreamWriter:
```Java
// Create writers
final StringWriter writer = new StringWriter();
final XMLStreamWriter xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
final CDataXmlStreamWriter cdataWriter = new CDataXmlStreamWriter(xmlWriter);

// Create JAXB context with example class
final JAXBContext ctx = JAXBContext.newInstance(MyClassWithCData.class);
final MyClassWithCData testee = new MyClassWithCData("<whatever this=\"is\"/>");

// Convert instance to XML
marshal(ctx, testee, null, cdataWriter);
final String xml = writer.toString();

// Prints out the result
System.out.println(xml);
// <?xml version="1.0" ?><my-class-with-cdata><![CDATA[<whatever this="is"/>]]></my-class-with-cdata>

// Convert it back to object
final MyClassWithCData copy = unmarshal(xml, MyClassWithCData.class);

// Print out cdata content
System.out.println(copy.getContent());
// <whatever this="is"/>
```

A full example can be found here: [CDataJaxbExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/CDataJaxbExample.java)


### Wait for code to finish

The [WaitHelper](https://github.com/fuinorg/utils4j/blob/master/src/main/java/org/fuin/utils4j/WaitHelper.java) class supports waiting for some condition.

Example of waiting for a function to finish without an exception:
```Java
// Try 5 times and wait 100 millis between tries (wait at max 10 seconds)
final WaitHelper waitHelper = new WaitHelper(1000, 5);

// Example of waiting for a customer to be found
waitHelper.waitUntilNoMoreException(() -> {

// We want to wait some time to see if the CustomerNotFoundException
// disappears and a customer name is finally loaded
loadCustomerName(customerId);

}, Arrays.asList(CustomerNotFoundException.class));
```

Example of waiting for an expected customer name:
```Java
waitHelper.waitUntilResult(() -> {

// We want to wait some time to see if the CustomerNotFoundException
// disappears and a customer name is finally loaded
return loadCustomerName2(customerId);

}, Arrays.asList("Peter Parker, Inc"));
```

A full example can be found here: [WaitHelperExample.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/WaitHelperExample.java)


### Find all JARs and classes in the classpath
Easily return a list of all classes or JAR files in the classpath.
```Java
// List CLASS files
for (final File file : Utils4J.classpathFiles(Utils4J::classFile)) {
System.out.println(file);
}

// List JAR files that are not located in the JRE directory
for (final File file : Utils4J.classpathFiles(Utils4J::nonJreJarFile)) {
System.out.println(file);
}

// List JAR files that are located in the JRE directory
for (final File file : Utils4J.classpathFiles(Utils4J::jreJarFile)) {
System.out.println(file);
}

// List JAR files that are located in the boot path of the JRE
for (final File file : Utils4J.pathsFiles(System.getProperty("sun.boot.class.path"), Utils4J::jreJarFile)) {
System.out.println(file);
}
```
A full example can be found here: [FindJarsAndClassesInClasspath.java](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/examples/FindJarsAndClassesInClasspath.java)

### Analyze classes in the classpath with Jandex
Easily find matching types from all classes or JAR files in the classpath using [Jandex](https://github.com/wildfly/jandex)
```Java
List<File> knownFiles = new ArrayList<>();
Indexer indexer = new Indexer();
JandexUtils.indexClasspath((URLClassLoader) this.getClass().getClassLoader(), indexer, knownFiles);
Index index = indexer.complete();
Set<ClassInfo> implementors = index.getAllKnownImplementors(DotName.createSimple(List.class.getName()));

// Print all classes that implement the 'List' interface
for (ClassInfo ci : implementors) {
System.out.println(ci.name().toString());
}

// Print all files ("*.jar" and ".class") that were analyzed
for (File file : knownFiles) {
System.out.println(file);
}
```
A test that shows the usage can be found here: [JandexUtilsTest](https://github.com/fuinorg/utils4j/blob/master/src/test/java/org/fuin/utils4j/JandexUtilsTest.java)

**Caution** - You must explicitly add the Jandex dependency to your POM if you want to use this feature, because it's defined as optional here.

```xml
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.0.4.Final</version>
</dependency>
```


* * *

##Snapshots
## Snapshots

Snapshots can be found on the [OSS Sonatype Snapshots Repository](http://oss.sonatype.org/content/repositories/snapshots/org/fuin "Snapshot Repository").

@@ -101,5 +267,3 @@ Add the following to your .m2/settings.xml to enable snapshots in your Maven bui
</snapshots>
</repository>
```


Loading