-
Notifications
You must be signed in to change notification settings - Fork 197
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
Support javac as a compiler for Tycho #3350
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -573,6 +573,7 @@ public List<String> getClasspathElements() throws MojoExecutionException { | |
final List<String> classpath = new ArrayList<>(); | ||
Set<String> seen = new HashSet<>(); | ||
Set<String> includedPathes = new HashSet<>(); | ||
boolean useAccessRules = JDT_COMPILER_ID.equals(compilerId); | ||
for (ClasspathEntry cpe : getClasspath()) { | ||
Stream<File> classpathLocations = Stream | ||
.concat(cpe.getLocations().stream(), | ||
|
@@ -581,7 +582,7 @@ public List<String> getClasspathElements() throws MojoExecutionException { | |
.filter(AbstractOsgiCompilerMojo::isValidLocation).distinct(); | ||
classpathLocations.forEach(location -> { | ||
String path = location.getAbsolutePath(); | ||
String entry = path + toString(cpe.getAccessRules()); | ||
String entry = path + toString(cpe.getAccessRules(), useAccessRules); | ||
if (seen.add(entry)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all but the first entry There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what you want to suggest here, the whole "see" part is that a path could apear multiple times (e.g. with different environments) so it is to make the list not contain it more than once ... |
||
includedPathes.add(path); | ||
classpath.add(entry); | ||
|
@@ -646,19 +647,22 @@ protected BundleProject getBundleProject() throws MojoExecutionException { | |
return (BundleProject) projectType; | ||
} | ||
|
||
private String toString(Collection<AccessRule> rules) { | ||
StringJoiner result = new StringJoiner(RULE_SEPARATOR, "[", "]"); // include all | ||
if (rules != null) { | ||
for (AccessRule rule : rules) { | ||
result.add((rule.isDiscouraged() ? "~" : "+") + rule.getPattern()); | ||
private String toString(Collection<AccessRule> rules, boolean useAccessRules) { | ||
if (useAccessRules) { | ||
StringJoiner result = new StringJoiner(RULE_SEPARATOR, "[", "]"); // include all | ||
if (rules != null) { | ||
for (AccessRule rule : rules) { | ||
result.add((rule.isDiscouraged() ? "~" : "+") + rule.getPattern()); | ||
} | ||
result.add(RULE_EXCLUDE_ALL); | ||
} else { | ||
// include everything, not strictly necessary, but lets make this obvious | ||
//result.append("[+**/*]"); | ||
return ""; | ||
} | ||
result.add(RULE_EXCLUDE_ALL); | ||
} else { | ||
// include everything, not strictly necessary, but lets make this obvious | ||
//result.append("[+**/*]"); | ||
return ""; | ||
return result.toString(); | ||
} | ||
return result.toString(); | ||
return ""; | ||
} | ||
|
||
@Override | ||
|
@@ -719,7 +723,7 @@ protected CompilerConfiguration getCompilerConfiguration(List<String> compileSou | |
List<Entry<String, String>> copy = new ArrayList<>( | ||
compilerConfiguration.getCustomCompilerArgumentsEntries()); | ||
compilerConfiguration.getCustomCompilerArgumentsEntries().clear(); | ||
compilerConfiguration.addCompilerCustomArgument("-properties", prefsFilePath); | ||
addCompilerCustomArgument(compilerConfiguration, "-properties", prefsFilePath); | ||
compilerConfiguration.getCustomCompilerArgumentsEntries().addAll(copy); | ||
} | ||
} | ||
|
@@ -738,7 +742,7 @@ protected CompilerConfiguration getCompilerConfiguration(List<String> compileSou | |
if (jreClasspathEntry.isModule()) { | ||
Collection<String> modules = jreClasspathEntry.getLimitModules(); | ||
if (!modules.isEmpty()) { | ||
compilerConfiguration.addCompilerCustomArgument("--limit-modules", String.join(",", modules)); | ||
addCompilerCustomArgument(compilerConfiguration, "--limit-modules", String.join(",", modules)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a standard javac option, too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems not to be a standard plexus compiler option so I'm not sure how to handle this gracefully... |
||
} | ||
} | ||
} | ||
|
@@ -782,7 +786,7 @@ private void configureCompilerLog(CompilerConfiguration compilerConfiguration) t | |
fileExtension = "log"; | ||
} | ||
logPath = logPath + logFileName + "." + fileExtension; | ||
compilerConfiguration.addCompilerCustomArgument("-log", logPath); | ||
addCompilerCustomArgument(compilerConfiguration, "-log", logPath); | ||
} | ||
|
||
private void configureBootclasspathAccessRules(CompilerConfiguration compilerConfiguration) | ||
|
@@ -811,8 +815,8 @@ private void configureBootclasspathAccessRules(CompilerConfiguration compilerCon | |
.addAll(getBundleProject().getBootClasspathExtraAccessRules(DefaultReactorProject.adapt(project))); | ||
} | ||
if (!accessRules.isEmpty()) { | ||
compilerConfiguration.addCompilerCustomArgument("org.osgi.framework.system.packages", | ||
toString(accessRules)); | ||
addCompilerCustomArgument(compilerConfiguration, "org.osgi.framework.system.packages", | ||
toString(accessRules, true)); | ||
} | ||
} | ||
|
||
|
@@ -837,7 +841,7 @@ private void configureJavaHome(CompilerConfiguration compilerConfiguration) thro | |
.orElseThrow(() -> new MojoExecutionException( | ||
"useJDK = BREE configured, but no toolchain of type 'jdk' with id '" + toolchainId | ||
+ "' found. See https://maven.apache.org/guides/mini/guide-using-toolchains.html")); | ||
compilerConfiguration.addCompilerCustomArgument("use.java.home", osgiToolchain.getJavaHome()); | ||
addCompilerCustomArgument(compilerConfiguration, "use.java.home", osgiToolchain.getJavaHome()); | ||
configureBootClassPath(compilerConfiguration, osgiToolchain); | ||
} | ||
} | ||
|
@@ -851,14 +855,22 @@ private void configureBootClassPath(CompilerConfiguration compilerConfiguration, | |
if (includeParent != null) { | ||
Xpp3Dom[] includes = includeParent.getChildren("include"); | ||
if (includes.length > 0) { | ||
compilerConfiguration.addCompilerCustomArgument("-bootclasspath", scanBootclasspath( | ||
addCompilerCustomArgument(compilerConfiguration, "-bootclasspath", scanBootclasspath( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bootclasspath is a standard javac option. Skipping this might cause surprises. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems not to be a standard plexus compiler option so I'm not sure how to handle this gracefully... |
||
osgiToolchain.getJavaHome(), includes, bootClassPath.getChild("excludes"))); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected boolean addCompilerCustomArgument(CompilerConfiguration compilerConfiguration, String key, String value) { | ||
if (JDT_COMPILER_ID.equals(compilerId)) { | ||
compilerConfiguration.addCompilerCustomArgument(key, value); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private String scanBootclasspath(String javaHome, Xpp3Dom[] includes, Xpp3Dom excludeParent) { | ||
DirectoryScanner scanner = new DirectoryScanner(); | ||
scanner.setBasedir(javaHome); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.eclipse.tycho.it</groupId> | ||
<artifactId>javac.parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>pom</packaging> | ||
<properties> | ||
<tycho-version>5.0.0-SNAPSHOT</tycho-version> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-maven-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-compiler-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<configuration> | ||
<compilerId>javac</compilerId> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<modules> | ||
<module>simple</module> | ||
</modules> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-SymbolicName: simple | ||
Bundle-Version: 1.0.0.qualifier |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.tycho.it</groupId> | ||
<artifactId>javac.parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>simple</artifactId> | ||
|
||
<packaging>eclipse-plugin</packaging> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012 SAP AG and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* SAP AG - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
public class Test | ||
{ | ||
public static void main(String[] args) { | ||
int a = 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.test; | ||
|
||
import org.apache.maven.it.Verifier; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test for the tycho-compiler-plugin | ||
*/ | ||
public class CompilerPluginTest extends AbstractTychoIntegrationTest { | ||
|
||
@Test | ||
public void testJavac() throws Exception { | ||
Verifier verifier = getVerifier("tycho-compiler-plugin/javac", true, true); | ||
verifier.executeGoal("compile"); | ||
verifier.verifyErrorFreeLog(); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@laeubi This class
AbstractOsgiCompilerMojo
does not contain any JavaDoc on the class declaration itself. It makes me wonder if it is even supposed to work with javac, given that the plain Java compiler does not have any understanding of OSGI semantics.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compilation actually do not require much of OSGi, ECJ supports "restrictions" on classpath entries but
javac
not as far as I know so thats the main difference here, also the target and source levels are derived from the manifest if possible.