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

Avoid Maven imports in core/deployment #28318

Merged
merged 1 commit into from
Oct 1, 2022
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
5 changes: 5 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,11 @@
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<version>${forbiddenapis-maven-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
3 changes: 3 additions & 0 deletions core/deployment/banned-signatures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@defaultMessage Don't use Maven classes. They won't be available when using Gradle.
org.apache.maven.**
org.codehaus.plexus.**
22 changes: 22 additions & 0 deletions core/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,28 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<executions>
<execution>
<id>verify-forbidden-apis</id>
<configuration>
<!-- if the used Java version is too new, don't fail, just do nothing: -->
<failOnUnsupportedJava>false</failOnUnsupportedJava>
<signaturesFiles>
<signaturesFile>./banned-signatures.txt</signaturesFile>
</signaturesFiles>
<failOnMissingClasses>false</failOnMissingClasses>
<ignoreSignaturesOfMissingClasses>true</ignoreSignaturesOfMissingClasses>
</configuration>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import java.util.function.Consumer;
import java.util.function.Predicate;

import org.apache.maven.shared.utils.cli.CommandLineException;
import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.jboss.logging.Logger;
import org.jboss.logmanager.formatters.ColorPatternFormatter;
Expand All @@ -47,6 +45,7 @@
import io.quarkus.deployment.dev.testing.MessageFormat;
import io.quarkus.deployment.dev.testing.TestSupport;
import io.quarkus.deployment.steps.ClassTransformingBuildStep;
import io.quarkus.deployment.util.CommandLineUtil;
import io.quarkus.dev.appstate.ApplicationStartException;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.dev.spi.DeploymentFailedStartHandler;
Expand Down Expand Up @@ -122,8 +121,8 @@ public void accept(Integer integer) {
public void accept(String args) {
try {
context.setArgs(
CommandLineUtils.translateCommandline(args));
} catch (CommandLineException e) {
CommandLineUtil.translateCommandline(args));
} catch (Exception e) {
log.error("Failed to parse command line", e);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.jboss.logging.Logger;

import io.quarkus.bootstrap.app.QuarkusBootstrap;
import io.quarkus.deployment.dev.DevModeContext.ModuleInfo;
import io.quarkus.deployment.util.CommandLineUtil;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.runtime.logging.JBossVersion;
import io.quarkus.runtime.util.JavaVersionUtil;
Expand Down Expand Up @@ -476,7 +476,7 @@ protected void prepare() throws Exception {
args.add("-jar");
args.add(tempFile.getAbsolutePath());
if (applicationArgs != null) {
args.addAll(Arrays.asList(CommandLineUtils.translateCommandline(applicationArgs)));
args.addAll(Arrays.asList(CommandLineUtil.translateCommandline(applicationArgs)));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package io.quarkus.deployment.util;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
* This class contains code coming from org.apache.maven.shared.utils.cli.CommandLineUtils.
* <p>
* We don't want to directly use code coming from Maven as this artifact should be Maven-agnostic.
*
* @author <a href="mailto:[email protected]">Trygve Laugst&oslash;l </a>
*/
public final class CommandLineUtil {

private CommandLineUtil() {
}

/**
* @param toProcess The command line to translate.
* @return The array of translated parts.
* @throws IllegalStateException in case of unbalanced quotes.
*/
public static String[] translateCommandline(String toProcess) {
if ((toProcess == null) || (toProcess.length() == 0)) {
return new String[0];
}

// parse with a simple finite state machine

final int normal = 0;
final int inQuote = 1;
final int inDoubleQuote = 2;
boolean inEscape = false;
int state = normal;
final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' \\", true);
List<String> tokens = new ArrayList<String>();
StringBuilder current = new StringBuilder();

while (tok.hasMoreTokens()) {
String nextTok = tok.nextToken();
switch (state) {
case inQuote:
if ("\'".equals(nextTok)) {
if (inEscape) {
current.append(nextTok);
inEscape = false;
} else {
state = normal;
}
} else {
current.append(nextTok);
inEscape = "\\".equals(nextTok);
}
break;
case inDoubleQuote:
if ("\"".equals(nextTok)) {
if (inEscape) {
current.append(nextTok);
inEscape = false;
} else {
state = normal;
}
} else {
current.append(nextTok);
inEscape = "\\".equals(nextTok);
}
break;
default:
if ("\'".equals(nextTok)) {
if (inEscape) {
inEscape = false;
current.append(nextTok);
} else {
state = inQuote;
}
} else if ("\"".equals(nextTok)) {
if (inEscape) {
inEscape = false;
current.append(nextTok);
} else {
state = inDoubleQuote;
}
} else if (" ".equals(nextTok)) {
if (current.length() != 0) {
tokens.add(current.toString());
current.setLength(0);
}
} else {
current.append(nextTok);
inEscape = "\\".equals(nextTok);
}
break;
}
}

if (current.length() != 0) {
tokens.add(current.toString());
}

if ((state == inQuote) || (state == inDoubleQuote)) {
throw new IllegalStateException("unbalanced quotes in " + toProcess);
}

return tokens.toArray(new String[tokens.size()]);
}
}
1 change: 0 additions & 1 deletion extensions/hibernate-orm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<plugin>
<groupId>de.thetaphi</groupId>
<artifactId>forbiddenapis</artifactId>
<version>${forbiddenapis-maven-plugin.version}</version>
<executions>
<execution>
<id>verify-forbidden-apis</id>
Expand Down