|
| 1 | +/*BEGIN_COPYRIGHT_BLOCK |
| 2 | + * |
| 3 | + * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu) |
| 4 | + * All rights reserved. |
| 5 | + * |
| 6 | + * Redistribution and use in source and binary forms, with or without |
| 7 | + * modification, are permitted provided that the following conditions are met: |
| 8 | + * * Redistributions of source code must retain the above copyright |
| 9 | + * notice, this list of conditions and the following disclaimer. |
| 10 | + * * Redistributions in binary form must reproduce the above copyright |
| 11 | + * notice, this list of conditions and the following disclaimer in the |
| 12 | + * documentation and/or other materials provided with the distribution. |
| 13 | + * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the |
| 14 | + * names of its contributors may be used to endorse or promote products |
| 15 | + * derived from this software without specific prior written permission. |
| 16 | + * |
| 17 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 20 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 21 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 22 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 23 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 24 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 25 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 26 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + * |
| 29 | + * This software is Open Source Initiative approved Open Source Software. |
| 30 | + * Open Source Initative Approved is a trademark of the Open Source Initiative. |
| 31 | + * |
| 32 | + * This file is part of DrJava. Download the current version of this project |
| 33 | + * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ |
| 34 | + * |
| 35 | + * END_COPYRIGHT_BLOCK*/ |
| 36 | + |
| 37 | +package edu.rice.cs.drjava.model.compiler.descriptors; |
| 38 | + |
| 39 | +import java.io.File; |
| 40 | +import java.io.FileNotFoundException; |
| 41 | +import java.io.IOException; |
| 42 | +import java.util.Set; |
| 43 | +import java.util.HashSet; |
| 44 | +import java.util.Collections; |
| 45 | +import java.util.jar.JarFile; |
| 46 | +import edu.rice.cs.plt.reflect.JavaVersion; |
| 47 | +import edu.rice.cs.plt.iter.IterUtil; |
| 48 | +import edu.rice.cs.plt.io.IOUtil; |
| 49 | +import edu.rice.cs.plt.lambda.LambdaUtil; |
| 50 | +import edu.rice.cs.plt.lambda.Predicate; |
| 51 | + |
| 52 | +import edu.rice.cs.drjava.model.JDKDescriptor; |
| 53 | + |
| 54 | +/** The description of the SoyLatte JDK. */ |
| 55 | +public class SoyLatteDescriptor extends JDKDescriptor { |
| 56 | + /** Return the name of this JDK. |
| 57 | + * @return name */ |
| 58 | + public String getName() { |
| 59 | + return "SoyLatte"; |
| 60 | + } |
| 61 | + |
| 62 | + /** Packages to shadow when loading a new tools.jar. If we don't shadow these classes, we won't |
| 63 | + * be able to load distinct versions for each tools.jar library. These should be verified whenever |
| 64 | + * a new Java version is released. (We can't just shadow *everything* because some classes, at |
| 65 | + * least in OS X's classes.jar, can only be loaded by the JVM.) |
| 66 | + * |
| 67 | + * @return set of packages that need to be shadowed |
| 68 | + */ |
| 69 | + public Set<String> getToolsPackages() { |
| 70 | + HashSet<String> set = new HashSet<String>(); |
| 71 | + Collections.addAll(set, new String[] { |
| 72 | + // Additional from 6 tools.jar: |
| 73 | + "com.sun.codemodel", |
| 74 | + "com.sun.istack.internal.tools", // other istack packages are in rt.jar |
| 75 | + "com.sun.istack.internal.ws", |
| 76 | + "com.sun.source", |
| 77 | + "com.sun.xml.internal.dtdparser", // other xml.internal packages are in rt.jar |
| 78 | + "com.sun.xml.internal.rngom", |
| 79 | + "com.sun.xml.internal.xsom", |
| 80 | + "org.relaxng", |
| 81 | + "javax.lang.element" |
| 82 | + }); |
| 83 | + return set; |
| 84 | + } |
| 85 | + |
| 86 | + /** Returns a list of directories that should be searched for tools.jar and classes.jar files. |
| 87 | + * @return list of directories to search */ |
| 88 | + public Iterable<File> getSearchDirectories() { |
| 89 | + if (System.getProperty("os.name").toLowerCase().indexOf("mac")<0) return IterUtil.empty(); // Mac only |
| 90 | + Iterable<File> roots = IterUtil.asIterable(new File[] { |
| 91 | + new File("/usr/local/soylatte"), |
| 92 | + new File("/usr/local") |
| 93 | + }); |
| 94 | + Predicate<File> subdirFilter = LambdaUtil.or(IOUtil.regexCanonicalCaseFilePredicate("\\d+\\.\\d+\\.\\d+"), |
| 95 | + IOUtil.regexCanonicalCaseFilePredicate("soylatte.*")); |
| 96 | + Iterable<File> dirs = IterUtil.empty(); |
| 97 | + for(File d: roots) { |
| 98 | + dirs = IterUtil.compose(dirs, IOUtil.attemptListFilesAsIterable(d, subdirFilter)); |
| 99 | + } |
| 100 | + return dirs; |
| 101 | + } |
| 102 | + |
| 103 | + /** Returns a list of files that should be searched if they contain a compiler. |
| 104 | + * @return list of files to search */ |
| 105 | + public Iterable<File> getSearchFiles() { |
| 106 | + if (System.getProperty("os.name").toLowerCase().indexOf("mac")<0) return IterUtil.empty(); // Mac only |
| 107 | + return IterUtil.asIterable(new File[] { |
| 108 | + new File("/usr/local/soylatte/lib/classes.jar"), |
| 109 | + new File("/usr/local/soylatte/lib/tools.jar") |
| 110 | + }); |
| 111 | + } |
| 112 | + |
| 113 | + /** True if this is a compound JDK and needs a fully featured JDK to operate. |
| 114 | + * @return true if compound JDK (e.g. NextGen, Mint, Habanero). */ |
| 115 | + public boolean isCompound() { return false; } |
| 116 | + |
| 117 | + /** Return true if the file (jar file or directory) contains the compiler. |
| 118 | + * @return true if the file contains the compiler */ |
| 119 | + public boolean containsCompiler(File f) { |
| 120 | + if (System.getProperty("os.name").toLowerCase().indexOf("mac")<0) return false; // Mac only |
| 121 | + return Util.exists(f, |
| 122 | + "sun/tools/javac/Main.class", |
| 123 | + "com/sun/tools/javac/main/JavaCompiler.class", |
| 124 | + "com/sun/tools/javac/util/Context.class", |
| 125 | + "com/sun/tools/javac/util/Name.class", |
| 126 | + "com/sun/tools/javac/util/Options.class", |
| 127 | + "com/sun/tools/javac/util/Position.class"); |
| 128 | + } |
| 129 | + |
| 130 | + /** Return the class name of the compiler adapter. |
| 131 | + * @return class name of compiler, or null if no compiler */ |
| 132 | + public String getAdapterForCompiler() { return "edu.rice.cs.drjava.model.compiler.Javac160Compiler"; } |
| 133 | + |
| 134 | + /** Return the class name of the debugger adapter. |
| 135 | + * @return class name of debugger, or null if no debugger */ |
| 136 | + public String getAdapterForDebugger() { return null; } |
| 137 | + |
| 138 | + /** Return the minimum Java version required to use this JDK. |
| 139 | + * @return minimum version */ |
| 140 | + public JavaVersion getMinimumMajorVersion() { return JavaVersion.JAVA_6; } |
| 141 | + |
| 142 | + /** Return the list of additional files required to use the compiler. |
| 143 | + * The compiler was found in the specified file. This method may have to search the user's hard drive, e.g. |
| 144 | + * by looking relative to compiler.getParentFile(), by checking environment variables, or by looking in |
| 145 | + * certain OS-specific directories. |
| 146 | + * @param compiler location where the compiler was fund |
| 147 | + * @return list of additional files that need to be available */ |
| 148 | + public Iterable<File> getAdditionalCompilerFiles(File compiler) throws FileNotFoundException { |
| 149 | + File parentDir = compiler.getParentFile(); |
| 150 | + return IterUtil.make(Util.oneOf(parentDir, "../jre/lib/rt.jar")); |
| 151 | + } |
| 152 | + |
| 153 | + public String toString() { return getClass().getSimpleName()+" --> "+getAdapterForCompiler(); } |
| 154 | +} |
0 commit comments