-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including the support for requires.nb.javac for source > 8 in apisupp…
…ort.ant.
- Loading branch information
Showing
7 changed files
with
317 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
...rt/apisupport.ant/src/org/netbeans/modules/apisupport/project/SetupLimitModulesProbe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.netbeans.modules.apisupport.project; | ||
|
||
import com.sun.source.util.JavacTask; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.lang.model.element.ModuleElement; | ||
import javax.lang.model.element.ModuleElement.RequiresDirective; | ||
import javax.lang.model.util.ElementFilter; | ||
import javax.tools.SimpleJavaFileObject; | ||
import javax.tools.ToolProvider; | ||
|
||
/** | ||
* There's a copy of this class in nbbuild/antsrc/org/netbeans/nbbuild/extlibs/SetupLimitModulesProbe.java. | ||
* Please make sure this are kept in sync. | ||
*/ | ||
public class SetupLimitModulesProbe { | ||
|
||
public static void main(String[] args) throws IOException { | ||
String release = args[0]; | ||
|
||
String[] excludedModules = | ||
Arrays.stream(args) | ||
.skip(1) | ||
.toArray(s -> new String[s]); | ||
|
||
String limitModules = computeLimitModules(release, excludedModules); | ||
|
||
System.out.println(limitModules); | ||
} | ||
|
||
public static String computeLimitModules(String release, String... excludedModulesIn) throws IOException { | ||
Set<String> excludedModules = new HashSet<>(List.of(excludedModulesIn)); | ||
List<String> options; | ||
|
||
if ("last".equals(release)) { | ||
options = List.of("--add-modules", "ALL-SYSTEM", "-classpath", ""); | ||
} else { | ||
options = List.of("--release", release, "-classpath", ""); | ||
} | ||
|
||
JavacTask task = (JavacTask) | ||
ToolProvider.getSystemJavaCompiler() | ||
.getTask(null, null, null, options, null, | ||
List.of(new JFOImpl(URI.create("mem://Test.java"), ""))); | ||
|
||
task.analyze(); | ||
|
||
String limitModules = | ||
task.getElements() | ||
.getAllModuleElements() | ||
.stream() | ||
.filter(m -> !m.getQualifiedName().toString().startsWith("jdk.internal.")) | ||
.filter(m -> !m.isUnnamed()) | ||
.filter(m -> canInclude(m, excludedModules)) | ||
.map(m -> m.getQualifiedName()) | ||
.collect(Collectors.joining(",")); | ||
|
||
return limitModules; | ||
} | ||
|
||
private static boolean canInclude(ModuleElement m, Set<String> excludes) { | ||
return Collections.disjoint(transitiveDependencies(m), excludes); | ||
} | ||
|
||
private static Set<String> transitiveDependencies(ModuleElement m) { | ||
List<ModuleElement> todo = new LinkedList<>(); | ||
Set<ModuleElement> seenModules = new HashSet<>(); | ||
|
||
todo.add(m); | ||
|
||
while (!todo.isEmpty()) { | ||
ModuleElement current = todo.remove(0); | ||
|
||
if (seenModules.add(current)) { | ||
for (RequiresDirective rd : ElementFilter.requiresIn(current.getDirectives())) { | ||
todo.add(rd.getDependency()); | ||
} | ||
} | ||
} | ||
|
||
return seenModules.stream() | ||
.map(c -> c.getQualifiedName().toString()) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
private static final class JFOImpl extends SimpleJavaFileObject { | ||
|
||
private final String content; | ||
|
||
public JFOImpl(URI uri, String content) { | ||
super(uri, Kind.SOURCE); | ||
this.content = content; | ||
} | ||
|
||
@Override | ||
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { | ||
return content; | ||
} | ||
|
||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...ort.ant/src/org/netbeans/modules/apisupport/project/queries/CompilerOptionsQueryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.netbeans.modules.apisupport.project.queries; | ||
|
||
import java.beans.PropertyChangeEvent; | ||
import java.beans.PropertyChangeListener; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.regex.Pattern; | ||
import javax.swing.event.ChangeListener; | ||
import org.netbeans.modules.apisupport.project.NbModuleProject; | ||
import org.netbeans.modules.apisupport.project.ui.customizer.SingleModuleProperties; | ||
import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation; | ||
import org.netbeans.spi.project.support.ant.PropertyEvaluator; | ||
import org.openide.filesystems.FileObject; | ||
import org.openide.util.ChangeSupport; | ||
import org.openide.util.WeakListeners; | ||
|
||
public class CompilerOptionsQueryImpl implements CompilerOptionsQueryImplementation { | ||
|
||
private final NbModuleProject project; | ||
private final AtomicReference<Result> cachedResult = new AtomicReference<>(); | ||
|
||
public CompilerOptionsQueryImpl(NbModuleProject project) { | ||
this.project = project; | ||
} | ||
|
||
@Override | ||
public Result getOptions(FileObject file) { | ||
Result result = cachedResult.get(); | ||
|
||
if (result == null) { | ||
result = cachedResult.updateAndGet(existing -> existing != null ? existing | ||
: new ResultImpl(project)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private static class ResultImpl extends Result implements PropertyChangeListener { | ||
|
||
private static final Pattern SPACE_SPLIT = Pattern.compile(" +"); | ||
private final PropertyEvaluator evaluator; | ||
private final ChangeSupport cs = new ChangeSupport(this); | ||
private List<? extends String> cachedArguments; | ||
|
||
public ResultImpl(NbModuleProject project) { | ||
this.evaluator = project.evaluator(); | ||
this.evaluator.addPropertyChangeListener(WeakListeners.propertyChange(this, this.evaluator)); | ||
} | ||
|
||
|
||
@Override | ||
public synchronized List<? extends String> getArguments() { | ||
List<? extends String> result = cachedArguments; | ||
|
||
if (result == null) { | ||
Map<String, String> properties = evaluator.getProperties(); | ||
String compilerArgs = properties.getOrDefault(SingleModuleProperties.JAVAC_COMPILERARGS, "") + | ||
" " + | ||
properties.getOrDefault(SingleModuleProperties.JAVAC_COMPILERARGS_INTERNAL_EXTRA, ""); | ||
|
||
compilerArgs = compilerArgs.trim(); | ||
|
||
if (compilerArgs.isEmpty()) { | ||
result = Collections.emptyList(); | ||
} else { | ||
result = Collections.unmodifiableList(Arrays.asList(SPACE_SPLIT.split(compilerArgs))); | ||
} | ||
|
||
cachedArguments = result; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public void addChangeListener(ChangeListener listener) { | ||
cs.addChangeListener(listener); | ||
} | ||
|
||
@Override | ||
public void removeChangeListener(ChangeListener listener) { | ||
cs.removeChangeListener(listener); | ||
} | ||
|
||
@Override | ||
public void propertyChange(PropertyChangeEvent pce) { | ||
synchronized (this) { | ||
cachedArguments = null; | ||
} | ||
cs.fireChange(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.