本文整理汇总了Java中org.netbeans.api.java.platform.JavaPlatformManager类的典型用法代码示例。如果您正苦于以下问题:Java JavaPlatformManager类的具体用法?Java JavaPlatformManager怎么用?Java JavaPlatformManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaPlatformManager类属于org.netbeans.api.java.platform包,在下文中一共展示了JavaPlatformManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findClassPath
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
public ClassPath findClassPath(FileObject file, String type) {
if(ClassPath.SOURCE.equals(type)){
return this.classPath;
}
if (ClassPath.COMPILE.equals(type)){
try {
URL eclipselinkJarUrl = Class.forName("javax.persistence.EntityManager").getProtectionDomain().getCodeSource().getLocation();
URL[] urls = new URL[]{FileUtil.getArchiveRoot(eclipselinkJarUrl)};
return ClassPathSupport.createClassPath(urls);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
if (ClassPath.BOOT.equals(type)){
return JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
}
return null;
}
示例2: setUp
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
protected void setUp() throws Exception {
MockLookup.init();
clearWorkDir();
File userdir = new File(getWorkDir(), "userdir");
userdir.mkdirs();
System.setProperty("netbeans.user", userdir.getAbsolutePath());
srcFO = FileUtil.toFileObject(getWorkDir()).createFolder("src");
srcCPImpl = new ClassPathImpl(URLMapper.findURL(srcFO, URLMapper.INTERNAL));
srcCP = ClassPathFactory.createClassPath(srcCPImpl);
compileCPImpl = new ClassPathImpl();
compileCP = ClassPathFactory.createClassPath(compileCPImpl);
bootCP = JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries();
roots = new ArrayList<FileObject>();
roots.add(srcFO);
cpProvider = new ClassPathProviderImpl();
MockLookup.setInstances(cpProvider);
FileUtil.setMIMEType("java", "text/x-java");
}
示例3: findPlatformSources
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
/**
*/
private ClassPath findPlatformSources(final String javaExecutable) {
/* Copied from JavaAntLogger */
final JavaPlatform[] platforms = JavaPlatformManager.getDefault()
.getInstalledPlatforms();
for (int i = 0; i < platforms.length; i++) {
FileObject fo = platforms[i].findTool("java"); //NOI18N
if (fo != null) {
File f = FileUtil.toFile(fo);
if (f.getAbsolutePath().startsWith(javaExecutable)) {
return platforms[i].getSourceFolders();
}
}
}
return null;
}
示例4: existPlatform
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
private static boolean existPlatform(
@NullAllowed final Project prj,
@NonNull final PropertyEvaluator eval,
@NonNull final String platform) {
if (platform.equals("default_platform")) { // NOI18N
return true;
}
for (JavaPlatform plat : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
// XXX: this should be defined as PROPERTY somewhere
if (platform.equals(plat.getProperties().get(PLAT_PROP_ANT_NAME))) {
return plat.isValid();
}
}
return prj == null ?
false :
ProjectPlatform.forProject(prj, eval, "j2se") != null; //NOI18N //Todo: custom platform type?
}
示例5: getActivePlatform
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
@CheckForNull
private JavaPlatform getActivePlatform() {
final String activePlatformId = this.eval.getProperty(platformProp);
final JavaPlatformManager pm = JavaPlatformManager.getDefault();
if (activePlatformId == null) {
return pm.getDefaultPlatform();
}
final JavaPlatform[] installedPlatforms = pm.getPlatforms(
null,
new Specification(platformType, null));
for (JavaPlatform javaPlatform : installedPlatforms) {
final String antName = javaPlatform.getProperties().get(PLAT_PROP_ANT_NAME);
if (activePlatformId.equals(antName)) {
return javaPlatform;
}
}
return null;
}
示例6: findOwner
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
private J2SEPlatformImpl findOwner(final URL root) {
for (JavaPlatform p : JavaPlatformManager.getDefault().getPlatforms(null, new Specification(J2SEPlatformImpl.PLATFORM_J2SE, null))) {
if (!(p instanceof J2SEPlatformImpl)) {
//Cannot handle unknown platform
continue;
}
final J2SEPlatformImpl j2sep = (J2SEPlatformImpl) p;
if (!j2sep.isValid()) {
continue;
}
for (ClassPath.Entry entry : j2sep.getBootstrapLibraries().entries()) {
if (root.equals(entry.getURL())) {
return j2sep;
}
}
}
return null;
}
示例7: updateBuildProperties
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
private static boolean updateBuildProperties (EditableProperties ep) {
boolean changed = false;
JavaPlatform[] installedPlatforms = JavaPlatformManager.getDefault().getPlatforms(null, new Specification ("j2se",null)); //NOI18N
for (int i=0; i<installedPlatforms.length; i++) {
//Handle only platforms created by this module
if (!installedPlatforms[i].equals (JavaPlatformManager.getDefault().getDefaultPlatform()) && installedPlatforms[i] instanceof J2SEPlatformImpl) {
String systemName = ((J2SEPlatformImpl)installedPlatforms[i]).getAntName();
String key = PlatformConvertor.createName(systemName,"home"); //NOI18N
if (!ep.containsKey (key)) {
try {
PlatformConvertor.generatePlatformProperties(installedPlatforms[i], systemName, ep);
changed = true;
} catch (PlatformConvertor.BrokenPlatformException b) {
Logger.getLogger(J2SEPlatformModule.class.getName()).info("Platform: " + installedPlatforms[i].getDisplayName() +" is missing: " + b.getMissingTool());
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
}
}
}
}
return changed;
}
示例8: Result
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
public Result (
@NonNull final JavaPlatformManager jpm,
@NonNull final URL artifact,
@NonNull final Collection<? extends JavaPlatform> platforms) {
Parameters.notNull("jpm", jpm); //NOI18N
Parameters.notNull("artifact", artifact); //NOI18N
Parameters.notNull("platforms", platforms); //NOI18N
this.jpm = jpm;
this.artifact = artifact;
synchronized (this) {
this.platforms = new LinkedHashMap<>();
for (JavaPlatform platform : platforms) {
final PropertyChangeListener l = WeakListeners.propertyChange(this, platform);
platform.addPropertyChangeListener(l);
this.platforms.put(platform, l);
}
this.jpm.addPropertyChangeListener(WeakListeners.propertyChange(this, this.jpm));
}
}
示例9: adjustSpans
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
private void adjustSpans(Iterable<? extends Tree> original, String code) {
if (tree2Tag == null) {
return; //nothing to copy
}
java.util.List<Tree> linearized = new LinkedList<Tree>();
if (!new Linearize().scan(original, linearized) != Boolean.TRUE) {
return; //nothing to copy
}
ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty);
JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null, Arrays.asList(FileObjects.memoryFileObject("", "Scratch.java", code)));
com.sun.tools.javac.util.Context ctx = javacTask.getContext();
JavaCompiler.instance(ctx).genEndPos = true;
CompilationUnitTree tree = javacTask.parse().iterator().next(); //NOI18N
SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions();
ClassTree clazz = (ClassTree) tree.getTypeDecls().get(0);
new CopyTags(tree, sp).scan(clazz.getModifiers().getAnnotations(), linearized);
}
示例10: reformat
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
public static String reformat(String text, CodeStyle style, int rightMargin) {
StringBuilder sb = new StringBuilder(text);
ClassPath empty = ClassPathSupport.createClassPath(new URL[0]);
ClasspathInfo cpInfo = ClasspathInfo.create(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries(), empty, empty);
JavacTaskImpl javacTask = JavacParser.createJavacTask(cpInfo, null, null, null, null, null, null, null, Arrays.asList(FileObjects.memoryFileObject("","Scratch.java", text)));
com.sun.tools.javac.util.Context ctx = javacTask.getContext();
JavaCompiler.instance(ctx).genEndPos = true;
CompilationUnitTree tree = javacTask.parse().iterator().next(); //NOI18N
SourcePositions sp = JavacTrees.instance(ctx).getSourcePositions();
TokenSequence<JavaTokenId> tokens = TokenHierarchy.create(text, JavaTokenId.language()).tokenSequence(JavaTokenId.language());
for (Diff diff : Pretty.reformat(text, tokens, new TreePath(tree), sp, style, rightMargin)) {
int start = diff.getStartOffset();
int end = diff.getEndOffset();
sb.delete(start, end);
String t = diff.getText();
if (t != null && t.length() > 0) {
sb.insert(start, t);
}
}
return sb.toString();
}
示例11: mapJarToCtSym
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
@NonNull
private Pair<File,String> mapJarToCtSym(
@NonNull final File file) {
if (USE_CT_SYM && NAME_RT_JAR.equals(file.getName())) {
final FileObject fo = FileUtil.toFileObject(file);
if (fo != null) {
for (JavaPlatform jp : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
for (FileObject jdkFolder : jp.getInstallFolders()) {
if (FileUtil.isParentOf(jdkFolder, fo)) {
final FileObject ctSym = jdkFolder.getFileObject(PATH_CT_SYM);
File ctSymFile;
if (ctSym != null && (ctSymFile = FileUtil.toFile(ctSym)) != null) {
return Pair.<File,String>of(ctSymFile,PATH_RT_JAR_IN_CT_SYM);
}
}
}
}
}
}
return Pair.<File,String>of(file, null);
}
示例12: testIssue247469
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
public void testIssue247469() throws IOException {
final JavaPlatform jp = JavaPlatformManager.getDefault().getDefaultPlatform();
assertNotNull(jp);
final ClasspathInfo cpInfo = ClasspathInfo.create(jp.getBootstrapLibraries(), ClassPath.EMPTY, ClassPath.EMPTY);
assertNotNull(cpInfo);
final JavaSource js = JavaSource.create(cpInfo);
js.runUserActionTask(new Task<CompilationController>() {
@Override
public void run(final CompilationController cc) throws Exception {
final PackageElement packageElement = cc.getElements().getPackageElement("java.lang"); // NOI18N
for (Element elem : packageElement.getEnclosedElements()) {
if ("ProcessBuilder$1".equals(elem.getSimpleName().toString())) { // NOI18N
TypeElement te = (TypeElement) elem;
assertEquals(NestingKind.ANONYMOUS, te.getNestingKind());
break;
}
}
}
}, true);
}
示例13: findPlatformSources
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
/**
*/
private ClassPath findPlatformSources(final String javaExecutable) {
/*
* Copied from JavaAntLogger
*/
final JavaPlatform[] platforms = JavaPlatformManager.getDefault().getInstalledPlatforms();
for (int i = 0; i < platforms.length; i++) {
FileObject fo = platforms[i].findTool("java"); //NOI18N
if (fo != null) {
File f = FileUtil.toFile(fo);
//XXX - look for a "subpath" in case of forked JRE; is there a better way?
String path = f.getAbsolutePath();
if (path.startsWith(javaExecutable)
|| javaExecutable.startsWith(path.substring(0, path.length() - 8))) {
return platforms[i].getSourceFolders();
}
}
}
return null;
}
示例14: findJavaPlatforms
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
@NonNull
private Collection<? extends JavaPlatform> findJavaPlatforms(@NonNull final File jfxrt) {
final JavaPlatform[] jps = JavaPlatformManager.getDefault().getPlatforms(
null,
new Specification(
"j2se", //NOI18N
null));
final Collection<JavaPlatform> res = new ArrayList<JavaPlatform>(jps.length);
final FileObject jfxrfFo = FileUtil.toFileObject(jfxrt);
if (jfxrfFo != null) {
for (JavaPlatform jp : jps) {
for (FileObject installFolder : jp.getInstallFolders()) {
if (FileUtil.isParentOf(installFolder, jfxrfFo)) {
res.add(jp);
}
}
}
}
return res;
}
示例15: prepareClassPaths
import org.netbeans.api.java.platform.JavaPlatformManager; //导入依赖的package包/类
private ClassPath[] prepareClassPaths() {
Set<ClassPath> srcPaths = GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE);
Set<ClassPath> compilePaths = GlobalPathRegistry.getDefault().getPaths(ClassPath.COMPILE);
Set<ClassPath> bootPaths = GlobalPathRegistry.getDefault().getPaths(ClassPath.BOOT);
if (bootPaths.isEmpty()) {
bootPaths = Collections.singleton(JavaPlatformManager.getDefault().getDefaultPlatform().getBootstrapLibraries());
}
ClassPath[] cps = new ClassPath[3];
cps[0] = ClassPathSupport.createProxyClassPath(bootPaths.toArray(new ClassPath[0]));
cps[1] = ClassPathSupport.createProxyClassPath(compilePaths.toArray(new ClassPath[0]));
cps[2] = ClassPathSupport.createProxyClassPath(srcPaths.toArray(new ClassPath[0]));
return cps;
}