Skip to content

Commit

Permalink
Merge pull request #804 from jplag/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaglam authored Nov 17, 2022
2 parents 6fc9f77 + 60f9634 commit 7d17ab1
Show file tree
Hide file tree
Showing 69 changed files with 1,038 additions and 889 deletions.
6 changes: 6 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!--
Pull requests regarding major or minor updates need to target the `develop` branch.
Pull requests regarding patch updates need to target the `main` branch.
Please make sure to select the appropriate branch while creating the pull request.
For a reference on semantic versioning, see https://semver.org.
-->
27 changes: 22 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name: Deploy to Maven Central
name: Deploy to Maven Central & GitHub
on:
workflow_dispatch:
release:
types: [created]
jobs:
publish:
publish-maven-central:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Set maven settings.xml
uses: whelk-io/maven-settings-xml-action@v20
uses: whelk-io/maven-settings-xml-action@v21
with:
servers: '[{ "id": "ossrh", "username": "jplag", "password": "${{ secrets.OSSRH_TOKEN }}" }]'
- name: Import GPG key
Expand All @@ -26,3 +25,21 @@ jobs:
run: mvn -P deployment -U -B deploy
env:
GPG_PASSPHRASE: ${{ secrets.PGP_PW }}

publish-release-artifact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build JPlag
run: mvn -U -B clean package assembly:single

- name: Attach CLI to Release on GitHub
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: jplag.cli/target/jplag-*-jar-with-dependencies.jar
fail_on_unmatched_files: true
19 changes: 4 additions & 15 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</parent>
<artifactId>cli</artifactId>
<dependencies>
<!-- IMPORTANT: For Coverage testing, you have to add dependencies to the coverage-report project ! -->

<dependency>
<groupId>de.jplag</groupId>
<artifactId>jplag</artifactId>
Expand Down Expand Up @@ -103,7 +105,7 @@
<configuration>
<archive>
<manifest>
<mainClass>de.jplag.CLI</mainClass>
<mainClass>de.jplag.cli.CLI</mainClass>
<packageName>jplag</packageName>
</manifest>
</archive>
Expand All @@ -117,7 +119,7 @@
</descriptors>
<archive>
<manifest>
<mainClass>de.jplag.CLI</mainClass>
<mainClass>de.jplag.cli.CLI</mainClass>
<packageName>jplag</packageName>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
Expand All @@ -126,19 +128,6 @@
<finalName>jplag-${project.version}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report-aggregate</id>
<goals>
<goal>report-aggregate</goal>
</goals>
<phase>verify</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package de.jplag;

import static de.jplag.CommandLineArgument.BASE_CODE;
import static de.jplag.CommandLineArgument.CLUSTER_AGGLOMERATIVE_INTER_CLUSTER_SIMILARITY;
import static de.jplag.CommandLineArgument.CLUSTER_AGGLOMERATIVE_THRESHOLD;
import static de.jplag.CommandLineArgument.CLUSTER_ALGORITHM;
import static de.jplag.CommandLineArgument.CLUSTER_DISABLE;
import static de.jplag.CommandLineArgument.CLUSTER_METRIC;
import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_CDF;
import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_NONE;
import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_PERCENTILE;
import static de.jplag.CommandLineArgument.CLUSTER_PREPROCESSING_THRESHOLD;
import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_BANDWIDTH;
import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_KMEANS_ITERATIONS;
import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_MAX_RUNS;
import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_MIN_RUNS;
import static de.jplag.CommandLineArgument.CLUSTER_SPECTRAL_NOISE;
import static de.jplag.CommandLineArgument.DEBUG;
import static de.jplag.CommandLineArgument.EXCLUDE_FILE;
import static de.jplag.CommandLineArgument.LANGUAGE;
import static de.jplag.CommandLineArgument.MIN_TOKEN_MATCH;
import static de.jplag.CommandLineArgument.NEW_DIRECTORY;
import static de.jplag.CommandLineArgument.OLD_DIRECTORY;
import static de.jplag.CommandLineArgument.RESULT_FOLDER;
import static de.jplag.CommandLineArgument.ROOT_DIRECTORY;
import static de.jplag.CommandLineArgument.SHOWN_COMPARISONS;
import static de.jplag.CommandLineArgument.SIMILARITY_THRESHOLD;
import static de.jplag.CommandLineArgument.SUBDIRECTORY;
import static de.jplag.CommandLineArgument.SUFFIXES;
package de.jplag.cli;

import static de.jplag.cli.CommandLineArgument.BASE_CODE;
import static de.jplag.cli.CommandLineArgument.CLUSTER_AGGLOMERATIVE_INTER_CLUSTER_SIMILARITY;
import static de.jplag.cli.CommandLineArgument.CLUSTER_AGGLOMERATIVE_THRESHOLD;
import static de.jplag.cli.CommandLineArgument.CLUSTER_ALGORITHM;
import static de.jplag.cli.CommandLineArgument.CLUSTER_DISABLE;
import static de.jplag.cli.CommandLineArgument.CLUSTER_METRIC;
import static de.jplag.cli.CommandLineArgument.CLUSTER_PREPROCESSING_CDF;
import static de.jplag.cli.CommandLineArgument.CLUSTER_PREPROCESSING_NONE;
import static de.jplag.cli.CommandLineArgument.CLUSTER_PREPROCESSING_PERCENTILE;
import static de.jplag.cli.CommandLineArgument.CLUSTER_PREPROCESSING_THRESHOLD;
import static de.jplag.cli.CommandLineArgument.CLUSTER_SPECTRAL_BANDWIDTH;
import static de.jplag.cli.CommandLineArgument.CLUSTER_SPECTRAL_KMEANS_ITERATIONS;
import static de.jplag.cli.CommandLineArgument.CLUSTER_SPECTRAL_MAX_RUNS;
import static de.jplag.cli.CommandLineArgument.CLUSTER_SPECTRAL_MIN_RUNS;
import static de.jplag.cli.CommandLineArgument.CLUSTER_SPECTRAL_NOISE;
import static de.jplag.cli.CommandLineArgument.DEBUG;
import static de.jplag.cli.CommandLineArgument.EXCLUDE_FILE;
import static de.jplag.cli.CommandLineArgument.LANGUAGE;
import static de.jplag.cli.CommandLineArgument.MIN_TOKEN_MATCH;
import static de.jplag.cli.CommandLineArgument.NEW_DIRECTORY;
import static de.jplag.cli.CommandLineArgument.OLD_DIRECTORY;
import static de.jplag.cli.CommandLineArgument.RESULT_FOLDER;
import static de.jplag.cli.CommandLineArgument.ROOT_DIRECTORY;
import static de.jplag.cli.CommandLineArgument.SHOWN_COMPARISONS;
import static de.jplag.cli.CommandLineArgument.SIMILARITY_THRESHOLD;
import static de.jplag.cli.CommandLineArgument.SUBDIRECTORY;
import static de.jplag.cli.CommandLineArgument.SUFFIXES;

import java.io.File;
import java.security.SecureRandom;
Expand All @@ -45,10 +45,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.jplag.JPlag;
import de.jplag.JPlagResult;
import de.jplag.cli.logger.CollectedLoggerFactory;
import de.jplag.clustering.ClusteringOptions;
import de.jplag.clustering.Preprocessing;
import de.jplag.exceptions.ExitException;
import de.jplag.logger.CollectedLoggerFactory;
import de.jplag.options.JPlagOptions;
import de.jplag.reporting.reportobject.ReportObjectFactory;

Expand All @@ -58,7 +60,7 @@
*/
public final class CLI {

private static final Logger logger = LoggerFactory.getLogger("JPlag");
private static final Logger logger = LoggerFactory.getLogger(CLI.class);

private static final Random RANDOM = new SecureRandom();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag;
package de.jplag.cli;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.jplag;
package de.jplag.cli;

import static de.jplag.CLI.ADVANCED_GROUP;
import static de.jplag.CLI.CLUSTERING_GROUP_NAME;
import static de.jplag.cli.CLI.ADVANCED_GROUP;
import static de.jplag.cli.CLI.CLUSTERING_GROUP_NAME;
import static de.jplag.options.JPlagOptions.DEFAULT_SHOWN_COMPARISONS;
import static de.jplag.options.JPlagOptions.DEFAULT_SIMILARITY_THRESHOLD;
import static net.sourceforge.argparse4j.impl.Arguments.append;
Expand All @@ -20,6 +20,9 @@
import net.sourceforge.argparse4j.inf.FeatureControl;
import net.sourceforge.argparse4j.inf.Namespace;

import de.jplag.Language;
import de.jplag.Messages;
import de.jplag.NumberOfArgumentValues;
import de.jplag.clustering.ClusteringAlgorithm;
import de.jplag.clustering.ClusteringOptions;
import de.jplag.clustering.algorithm.InterClusterSimilarity;
Expand All @@ -34,7 +37,7 @@ public enum CommandLineArgument {
NEW_DIRECTORY(new Builder("-new", String.class).nargs(NumberOfArgumentValues.ONE_OR_MORE_VALUES)),
OLD_DIRECTORY(new Builder("-old", String.class).nargs(NumberOfArgumentValues.ONE_OR_MORE_VALUES)),
LANGUAGE(
new Builder("-l", String.class).defaultsTo(de.jplag.java.Language.IDENTIFIER)
new Builder("-l", String.class).defaultsTo(new de.jplag.java.Language().getIdentifier())
.choices(LanguageLoader.getAllAvailableLanguageIdentifiers())),
BASE_CODE("-bc", String.class),

Expand Down Expand Up @@ -82,7 +85,7 @@ public enum CommandLineArgument {
* The identifier of the default {@link Language}.
* @see Language#getIdentifier()
*/
public static final String DEFAULT_LANGUAGE_IDENTIFIER = de.jplag.java.Language.IDENTIFIER;
public static final String DEFAULT_LANGUAGE_IDENTIFIER = new de.jplag.java.Language().getIdentifier();

private final String flag;
private final NumberOfArgumentValues numberOfValues;
Expand Down Expand Up @@ -126,7 +129,7 @@ public String flag() {
* @return the flag name of the command line argument without leading dashes and inner dashes replaced with underscores.
*/
public String flagWithoutDash() {
return flag.replaceAll("^-+", "").replaceAll("-", "_");
return flag.replaceAll("^-+", "").replace("-", "_");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag;
package de.jplag.cli;

import java.util.Collections;
import java.util.Map;
Expand All @@ -11,12 +11,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.jplag.Language;

/**
* This class contains methods to load {@link Language Languages}.
* @author Dominik Fuchss
*/
public final class LanguageLoader {
private static final Logger logger = LoggerFactory.getLogger("JPlag");
private static final Logger logger = LoggerFactory.getLogger(LanguageLoader.class);

private static Map<String, Language> cachedLanguageInstances = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.logger;
package de.jplag.cli.logger;

import java.io.PrintStream;
import java.io.Serial;
Expand Down Expand Up @@ -27,7 +27,12 @@ public final class CollectedLogger extends MarkerIgnoringBase {
private static final int LOG_LEVEL_WARN = LocationAwareLogger.WARN_INT;
private static final int LOG_LEVEL_ERROR = LocationAwareLogger.ERROR_INT;

private final int currentLogLevel = LOG_LEVEL_INFO;
/**
* The default log level that shall be used for external libraries (like Stanford Core NLP)
*/
private static final int LOG_LEVEL_FOR_EXTERNAL_LIBRARIES = LOG_LEVEL_ERROR;

private static final int CURRENT_LOG_LEVEL = LOG_LEVEL_INFO;

/**
* The short name of this simple log instance
Expand Down Expand Up @@ -117,7 +122,11 @@ private String computeShortName() {
}

private boolean isLevelEnabled(int logLevel) {
return logLevel >= currentLogLevel;
return logLevel >= (isJPlagLog() ? CURRENT_LOG_LEVEL : LOG_LEVEL_FOR_EXTERNAL_LIBRARIES);
}

private boolean isJPlagLog() {
return this.name.startsWith("de.jplag.");
}

private String renderLevel(int level) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.logger;
package de.jplag.cli.logger;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.logger;
package de.jplag.cli.logger;

import org.kohsuke.MetaInfServices;
import org.slf4j.ILoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.jplag.logger;
package de.jplag.cli.logger;

public record Triple<A, B, C> (A first, B second, C third) {
}
2 changes: 0 additions & 2 deletions cli/src/test/java/de/jplag/cli/BaseCodeOptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import org.junit.jupiter.api.Test;

import de.jplag.CommandLineArgument;

class BaseCodeOptionTest extends CommandLineInterfaceTest {

private static final String NAME = "BaseCodeName";
Expand Down
1 change: 0 additions & 1 deletion cli/src/test/java/de/jplag/cli/ClusteringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import org.junit.jupiter.api.Test;

import de.jplag.CommandLineArgument;
import de.jplag.clustering.Preprocessing;

class ClusteringTest extends CommandLineInterfaceTest {
Expand Down
4 changes: 1 addition & 3 deletions cli/src/test/java/de/jplag/cli/CommandLineInterfaceTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package de.jplag.cli;

import static de.jplag.CommandLineArgument.ROOT_DIRECTORY;
import static de.jplag.cli.CommandLineArgument.ROOT_DIRECTORY;
import static java.util.stream.Collectors.toSet;

import java.util.Arrays;

import net.sourceforge.argparse4j.inf.Namespace;

import de.jplag.CLI;
import de.jplag.CommandLineArgument;
import de.jplag.options.JPlagOptions;

/**
Expand Down
2 changes: 0 additions & 2 deletions cli/src/test/java/de/jplag/cli/LanguageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import de.jplag.CommandLineArgument;
import de.jplag.Language;
import de.jplag.LanguageLoader;

class LanguageTest extends CommandLineInterfaceTest {

Expand Down
2 changes: 0 additions & 2 deletions cli/src/test/java/de/jplag/cli/MinTokenMatchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import org.junit.jupiter.api.Test;

import de.jplag.CommandLineArgument;

class MinTokenMatchTest extends CommandLineInterfaceTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.junit.jupiter.api.Test;

import de.jplag.CommandLineArgument;
import de.jplag.options.JPlagOptions;

class SimiliarityThresholdTest extends CommandLineInterfaceTest {
Expand Down
1 change: 0 additions & 1 deletion cli/src/test/java/de/jplag/cli/StoredMatchesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.junit.jupiter.api.Test;

import de.jplag.CommandLineArgument;
import de.jplag.options.JPlagOptions;

class StoredMatchesTest extends CommandLineInterfaceTest {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/de/jplag/JPlagResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ private int[] calculateDistributionFor(List<JPlagComparison> comparisons, ToDoub
int index = (int) (similarity * SIMILARITY_DISTRIBUTION_SIZE); // divide similarity by bucket size to find index of correct bucket.
index = Math.min(index, SIMILARITY_DISTRIBUTION_SIZE - 1);// index is out of bounds when similarity is 1.0. decrease by one to count
// towards the highest value bucket
similarityDistribution[SIMILARITY_DISTRIBUTION_SIZE - 1 - index]++; // count comparison towards its determined bucket. bucket order is
// reversed, so that the highest value bucket has the lowest index
similarityDistribution[index]++; // count comparison towards its determined bucket.
}
return similarityDistribution;
}
Expand Down
Loading

0 comments on commit 7d17ab1

Please sign in to comment.