Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing the gradle java plugin with java-library #196

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "java"
id "java-library"
id 'maven-publish'
id 'signing'
id 'jacoco'
Expand Down Expand Up @@ -45,19 +45,22 @@ jacocoTestReport {
compileJava {
options.compilerArgs = ['-proc:none', '-Xlint:all','-Werror','-Xdiags:verbose']
}

compileTestJava {
options.compilerArgs = ['-proc:none', '-Xlint:all','-Werror','-Xdiags:verbose']
}

dependencies {
implementation 'net.sf.jopt-simple:jopt-simple:5.0.3'
api 'net.sf.jopt-simple:jopt-simple:5.0.3'
api 'com.google.code.gson:gson:2.8.9'
api 'org.freemarker:freemarker:2.3.30'

implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'org.apache.logging.log4j:log4j-api:2.17.1'
implementation 'org.apache.logging.log4j:log4j-core:2.15.0'
implementation 'org.freemarker:freemarker:2.3.30'
implementation 'com.google.code.gson:gson:2.2.2'
runtimeOnly 'org.apache.logging.log4j:log4j-core:2.17.1'

testImplementation 'commons-io:commons-io:2.11.0'
testImplementation 'org.testng:testng:6.9.6'
testImplementation 'org.testng:testng:7.7.0'
testImplementation 'org.mockito:mockito-core:4.6.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import joptsimple.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.broadinstitute.barclay.utils.Pair;
import org.broadinstitute.barclay.utils.Utils;

import java.io.BufferedReader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.broadinstitute.barclay.argparser;

import org.apache.commons.lang3.tuple.Pair;
import org.broadinstitute.barclay.utils.Pair;

import java.io.PrintStream;
import java.util.List;
Expand Down Expand Up @@ -91,6 +91,6 @@ interface ClpEnum {
* is the ArgumentDefinition object itself, and the second element is the actual value of the argument field. The second
* element will be null for uninitialized fields.
*/
<T> List<Pair<ArgumentDefinition, T>> gatherArgumentValuesOfType( final Class<T> type );
<T> List<Pair<ArgumentDefinition, T>> gatherArgumentValuesOfType(final Class<T> type );

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package org.broadinstitute.barclay.argparser;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.broadinstitute.barclay.utils.Pair;
import org.broadinstitute.barclay.utils.Utils;

import java.io.BufferedReader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.broadinstitute.barclay.argparser;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.broadinstitute.barclay.utils.Pair;
import org.broadinstitute.barclay.utils.Utils;

import java.io.PrintStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.broadinstitute.barclay.argparser;

import org.apache.commons.lang3.tuple.Pair;
import org.broadinstitute.barclay.utils.Pair;
import org.broadinstitute.barclay.utils.Utils;

import java.util.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.broadinstitute.barclay.help;

import jdk.javadoc.doclet.DocletEnvironment;
import org.apache.commons.lang3.tuple.Pair;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.broadinstitute.barclay.argparser.*;
import org.broadinstitute.barclay.help.scanners.JavaLanguageModelScanners;
import org.broadinstitute.barclay.utils.Pair;
import org.broadinstitute.barclay.utils.Utils;

import javax.lang.model.element.Element;
Expand Down
50 changes: 25 additions & 25 deletions src/main/java/org/broadinstitute/barclay/help/WDLTransforms.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.broadinstitute.barclay.help;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.broadinstitute.barclay.utils.Pair;

import java.io.File;
import java.net.URI;
Expand Down Expand Up @@ -51,53 +51,53 @@ public class WDLTransforms {
// the type. From a purely string perspective, some of these transforms are no-ops in that no actual
// conversion is required because the type names are identical in Java and WDL (i.e, File->File or
// String->String), but they're included here for completeness, and to document the allowed type transitions.
private final static Map<Class<?>, ImmutablePair<String, String>> javaToWDLTypeMap =
new HashMap<Class<?>, ImmutablePair<String, String>>() {
private final static Map<Class<?>, Pair<String, String>> javaToWDLTypeMap =
new HashMap<Class<?>, Pair<String, String>>() {
private static final long serialVersionUID = 1L;

{
put(String.class, new ImmutablePair<>("String", "String"));
put(String.class, new Pair<>("String", "String"));

// primitive (or boxed primitive) types
put(boolean.class, new ImmutablePair<>("boolean", "Boolean"));
put(Boolean.class, new ImmutablePair<>("Boolean", "Boolean"));
put(boolean.class, new Pair<>("boolean", "Boolean"));
put(Boolean.class, new Pair<>("Boolean", "Boolean"));

put(byte.class, new ImmutablePair<>("byte", "Int"));
put(Byte.class, new ImmutablePair<>("Byte", "Int"));
put(byte.class, new Pair<>("byte", "Int"));
put(Byte.class, new Pair<>("Byte", "Int"));

put(int.class, new ImmutablePair<>("int", "Int"));
put(Integer.class, new ImmutablePair<>("Integer", "Int"));
put(int.class, new Pair<>("int", "Int"));
put(Integer.class, new Pair<>("Integer", "Int"));

//NOTE: WDL has no long type, map to Int
put(long.class, new ImmutablePair<>("long", "Int"));
put(Long.class, new ImmutablePair<>("Long", "Int"));
put(long.class, new Pair<>("long", "Int"));
put(Long.class, new Pair<>("Long", "Int"));

put(float.class, new ImmutablePair<>("float", "Float"));
put(Float.class, new ImmutablePair<>("Float", "Float"));
put(double.class, new ImmutablePair<>("double", "Float"));
put(Double.class, new ImmutablePair<>("Double", "Float"));
put(float.class, new Pair<>("float", "Float"));
put(Float.class, new Pair<>("Float", "Float"));
put(double.class, new Pair<>("double", "Float"));
put(Double.class, new Pair<>("Double", "Float"));

// File/Path Types
put(File.class, new ImmutablePair<>("File", "File"));
put(File.class, new Pair<>("File", "File"));

put(URI.class, new ImmutablePair<>("URI", "String"));
put(URL.class, new ImmutablePair<>("URL", "String"));
put(URI.class, new Pair<>("URI", "String"));
put(URL.class, new Pair<>("URL", "String"));
}
};

// Map of Java collection argument types that the WDL generator knows how to convert to a WDL type, along with the
// corresponding string substitution that needs to be run on the (Barclay-generated) string that describes
// the type.
private final static Map<Class<?>, ImmutablePair<String, String>> javaCollectionToWDLCollectionTypeMap =
new HashMap<Class<?>, ImmutablePair<String, String>>() {
private final static Map<Class<?>, Pair<String, String>> javaCollectionToWDLCollectionTypeMap =
new HashMap<>() {
private static final long serialVersionUID = 1L;

{
put(List.class, new ImmutablePair<>("List", "Array"));
put(List.class, new Pair<>("List", "Array"));
// Note: occasionally there are @Arguments that are typed as "ArrayList"
put(ArrayList.class, new ImmutablePair<>("ArrayList", "Array"));
put(Set.class, new ImmutablePair<>("Set", "Array"));
put(EnumSet.class, new ImmutablePair<>("EnumSet", "Array"));
put(ArrayList.class, new Pair<>("ArrayList", "Array"));
put(Set.class, new Pair<>("Set", "Array"));
put(EnumSet.class, new Pair<>("EnumSet", "Array"));
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.broadinstitute.barclay.help;

import org.apache.commons.lang3.tuple.Pair;

import org.broadinstitute.barclay.argparser.*;
import org.broadinstitute.barclay.argparser.WorkflowProperties;
import org.broadinstitute.barclay.utils.Pair;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
Expand Down
83 changes: 83 additions & 0 deletions src/main/java/org/broadinstitute/barclay/utils/Pair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.broadinstitute.barclay.utils;

import org.apache.commons.lang3.builder.CompareToBuilder;

import java.io.Serial;
import java.io.Serializable;
import java.util.Map;

/**
* Simple Pair class
* @param left left of pair
* @param right right of pair
* @param <L> type of left
* @param <R> type of right
*/
public record Pair<L,R>(L left, R right) implements Map.Entry<L,R>, Comparable<Pair<L,R>>, Serializable {

@Serial
private static final long serialVersionUID= 1;

/**
* @return left()
*/
public L getLeft(){
return left;
}

/**
* @return right()
*/
public R getRight() {
return right;

}

/**
* @return left()
*/
@Override
public L getKey() {
return left;
}

/**
* @return right()
*/
@Override
public R getValue() {
return right;
}

/**
* This Pair is immutable so the value cannot be set.
*
* @param value is irrelevant since this is immutable
* @return UnsupporedOperationException
* @throws UnsupportedOperationException
*/
@Override
public R setValue(final R value) {
throw new UnsupportedOperationException("Pair is an immutable record");
}


/**
* @return a new Pair of left and right
*/
public static <L,R> Pair<L,R> of(L left, R right){
return new Pair<>(left, right);
}


/**
* First compare left, then compare right
* @param other the Pair to be compared.
*/
@Override
public int compareTo(final Pair<L,R> other) {
//This implemntation is take out of the commons lang Pair for consistency reasons
return new CompareToBuilder().append(getLeft(), other.left)
.append(getRight(), other.right).toComparison();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.broadinstitute.barclay.argparser;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

import org.broadinstitute.barclay.utils.Pair;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down