Permalink
Browse files

Move JDK utils to API.

Upgrade SWR to v2.
  • Loading branch information...
alesj committed Oct 25, 2012
1 parent 8bd6153 commit 574dc015d086438c4d44abae24345799e22c9600
@@ -1,23 +1,20 @@
/*
- * Copyright Red Hat Inc. and/or its affiliates and other contributors
- * as indicated by the authors tag. All rights reserved.
+ * Copyright 2011 Red Hat inc. and third party contributors as noted
+ * by the author tags.
+ * Licensed 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
*
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License version 2.
- *
- * This particular file is subject to the "Classpath" exception as provided in the
- * LICENSE file that accompanied this code.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License,
- * along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
+ * 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 com.redhat.ceylon.cmr.impl;
+
+package com.redhat.ceylon.cmr.api;
import java.io.BufferedReader;
import java.io.IOException;
@@ -29,52 +26,57 @@
import java.util.Map;
import java.util.Set;
-public class JDKPackageList {
-
+/**
+ * Hide JDK impl details here.
+ *
+ * @author Stéphane Épardaud <stef@epardaud.fr>
+ * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ */
+public class JDKUtils {
@FroMage

FroMage Oct 25, 2012

Owner

Man the compiler and ide need to be updated

@alesj

alesj Oct 25, 2012

Member

Yeah, but such things need to go into "api" package, not "impl", hence moved.
Can you do the update or should I?

@FroMage

FroMage Oct 25, 2012

Owner

I will :)

private final static String JDK7 = "package-list.jdk7";
private final static String JDK7_ORACLE = "package-list.oracle.jdk7";
-
- private static Map<String,Set<String>> jdkModules;
- private static Map<String,Set<String>> jdkOracleModules;
-
+
+ private static Map<String, Set<String>> jdkModules;
+ private static Map<String, Set<String>> jdkOracleModules;
+
private static synchronized void loadPackageList() {
- if(jdkModules != null)
+ if (jdkModules != null)
return;
jdkModules = loadModularPackageList(JDK7);
jdkOracleModules = loadModularPackageList(JDK7_ORACLE);
}
- private static Map<String,Set<String>> loadModularPackageList(String file) {
- try{
+ private static Map<String, Set<String>> loadModularPackageList(String file) {
+ try {
// not thread-safe, but that's OK because the caller is thread-safe
Map<String, Set<String>> jdkPackages = new HashMap<String, Set<String>>();
- InputStream inputStream = JDKPackageList.class.getResourceAsStream(file);
- if(inputStream == null){
- throw new RuntimeException("Failed to read JDK package list file from "+file+": your Ceylon installation is broken.");
+ InputStream inputStream = JDKUtils.class.getResourceAsStream(file);
+ if (inputStream == null) {
+ throw new RuntimeException("Failed to read JDK package list file from " + file + ": your Ceylon installation is broken.");
}
BufferedReader bis = new BufferedReader(new InputStreamReader(inputStream, "ASCII"));
Set<String> module = null;
String moduleName = null;
String pkg;
- while((pkg = bis.readLine()) != null){
+ while ((pkg = bis.readLine()) != null) {
// strip comments
int commentStart = pkg.indexOf('#');
- if(commentStart > -1)
+ if (commentStart > -1)
pkg = pkg.substring(0, commentStart);
// strip whitespace
pkg = pkg.trim();
// ignore empty lines
- if(pkg.isEmpty())
+ if (pkg.isEmpty())
continue;
// see if we start a new module
- if(pkg.startsWith("=")){
+ if (pkg.startsWith("=")) {
String name = pkg.substring(1).trim();
- if(name.isEmpty())
- throw new RuntimeException("Failed to read JDK module list file from "+file+": module has empty name");
+ if (name.isEmpty())
+ throw new RuntimeException("Failed to read JDK module list file from " + file + ": module has empty name");
// close previous module
- if(module != null){
- if(module.isEmpty())
- throw new RuntimeException("Failed to read JDK module list file from "+file+": module "+moduleName+" is empty");
+ if (module != null) {
+ if (module.isEmpty())
+ throw new RuntimeException("Failed to read JDK module list file from " + file + ": module " + moduleName + " is empty");
// save previous module
jdkPackages.put(moduleName, Collections.unmodifiableSet(module));
}
@@ -84,42 +86,42 @@ private static synchronized void loadPackageList() {
continue;
}
// add a package to the current module
- if(module == null)
- throw new RuntimeException("Failed to read JDK module list file from "+file+": adding package to undefined module");
+ if (module == null)
+ throw new RuntimeException("Failed to read JDK module list file from " + file + ": adding package to undefined module");
module.add(pkg);
}
bis.close();
// close previous module
- if(module != null){
- if(module.isEmpty())
- throw new RuntimeException("Failed to read JDK module list file from "+file+": module "+moduleName+" is empty");
+ if (module != null) {
+ if (module.isEmpty())
+ throw new RuntimeException("Failed to read JDK module list file from " + file + ": module " + moduleName + " is empty");
// save previous module
jdkPackages.put(moduleName, Collections.unmodifiableSet(module));
}
// sanity check
- if(jdkPackages.size() == 0)
- throw new RuntimeException("Failed to read JDK package list file from "+file+"(empty package set): your Ceylon installation is broken.");
+ if (jdkPackages.size() == 0)
+ throw new RuntimeException("Failed to read JDK package list file from " + file + "(empty package set): your Ceylon installation is broken.");
return Collections.unmodifiableMap(jdkPackages);
- }catch(IOException x){
- throw new RuntimeException("Failed to read JDK package list file from "+file+": your Ceylon installation is broken.", x);
+ } catch (IOException x) {
+ throw new RuntimeException("Failed to read JDK package list file from " + file + ": your Ceylon installation is broken.", x);
}
}
- public static boolean isJDKModule(String mod){
+ public static boolean isJDKModule(String mod) {
loadPackageList();
return jdkModules.containsKey(mod);
}
- public static boolean isJDKPackage(String mod, String pkg){
+ public static boolean isJDKPackage(String mod, String pkg) {
loadPackageList();
Set<String> packages = jdkModules.get(mod);
return packages != null && packages.contains(pkg);
}
- public static boolean isJDKAnyPackage(String pkg){
+ public static boolean isJDKAnyPackage(String pkg) {
loadPackageList();
- for(Set<String> packages : jdkModules.values()){
- if(packages.contains(pkg))
+ for (Set<String> packages : jdkModules.values()) {
+ if (packages.contains(pkg))
return true;
}
return false;
@@ -130,26 +132,26 @@ public static boolean isJDKAnyPackage(String pkg){
return jdkModules.keySet();
}
- public static Map<String,Set<String>> getJDKPackagesByModule() {
+ public static Set<String> getJDKPackagesByModule(String module) {
loadPackageList();
- return jdkModules;
+ return jdkModules.get(module);
}
- public static boolean isOracleJDKModule(String pkg){
+ public static boolean isOracleJDKModule(String pkg) {
loadPackageList();
return jdkOracleModules.containsKey(pkg);
}
- public static boolean isOracleJDKPackage(String mod, String pkg){
+ public static boolean isOracleJDKPackage(String mod, String pkg) {
loadPackageList();
Set<String> packages = jdkOracleModules.get(mod);
return packages != null && packages.contains(pkg);
}
- public static boolean isOracleJDKAnyPackage(String pkg){
+ public static boolean isOracleJDKAnyPackage(String pkg) {
loadPackageList();
- for(Set<String> packages : jdkOracleModules.values()){
- if(packages.contains(pkg))
+ for (Set<String> packages : jdkOracleModules.values()) {
+ if (packages.contains(pkg))
return true;
}
return false;
@@ -160,9 +162,8 @@ public static boolean isOracleJDKAnyPackage(String pkg){
return jdkOracleModules.keySet();
}
- public static Map<String,Set<String>> getOracleJDKPackagesByModule() {
+ public static Set<String> getOracleJDKPackagesByModule(String module) {
loadPackageList();
- return jdkOracleModules;
+ return jdkOracleModules.get(module);
}
-
}
View
@@ -47,7 +47,7 @@ slf4j-simple.url=
slf4j-simple.lib=${base.path}/${slf4j-simple.jar}
# ----- Combination of several Shrinkwrap and Maven JARs into one lib ---
-shrinkwrap-maven-uberjar.version=1.1.0-alpha-2
+shrinkwrap-maven-uberjar.version=2.0.0-alpha-4
shrinkwrap-maven-uberjar.jar=shrinkwrap-maven-uberjar-${shrinkwrap-maven-uberjar.version}.jar
shrinkwrap-maven-uberjar.url=
shrinkwrap-maven-uberjar.lib=${base.path}/${shrinkwrap-maven-uberjar.jar}
View
@@ -11,8 +11,8 @@
<!-- The Java source files for the module-resolver -->
<property name="cmr-api.src" location="${basedir}/api/src/main/java"/>
+ <property name="cmr-api.resources" location="${basedir}/api/src/main/resources"/>
<property name="cmr-impl.src" location="${basedir}/impl/src/main/java"/>
- <property name="cmr-impl.resources" location="${basedir}/impl/src/main/resources"/>
<property name="cmr-spi.src" location="${basedir}/spi/src/main/java"/>
<property name="cmr-webdav.src" location="${basedir}/webdav/src/main/java"/>
<property name="cmr-ceylon.src" location="${basedir}/ceylon/src/main/java"/>
@@ -122,12 +122,12 @@
<fileset dir="${cmr-api.src}">
<include name="**/*.java"/>
</fileset>
+ <fileset dir="${cmr-api.resources}">
+ <include name="**"/>
+ </fileset>
<fileset dir="${cmr-impl.src}">
<include name="**/*.java"/>
</fileset>
- <fileset dir="${cmr-impl.resources}">
- <include name="**"/>
- </fileset>
<fileset dir="${cmr-spi.src}">
<include name="**/*.java"/>
</fileset>
@@ -214,7 +214,7 @@
classpathref="compiler.classpath"
includeantruntime="false"/>
<copy todir="${build.classes}">
- <fileset dir="${cmr-impl.resources}">
+ <fileset dir="${cmr-api.resources}">
<include name="**"/>
</fileset>
<fileset dir="${cmr-maven.resources}">
@@ -23,6 +23,7 @@
import com.redhat.ceylon.cmr.api.ArtifactContext;
import com.redhat.ceylon.cmr.api.ArtifactResult;
import com.redhat.ceylon.cmr.api.ContentFinder;
+import com.redhat.ceylon.cmr.api.JDKUtils;
import com.redhat.ceylon.cmr.api.ModuleQuery;
import com.redhat.ceylon.cmr.api.ModuleSearchResult;
import com.redhat.ceylon.cmr.api.ModuleVersionDetails;
@@ -41,16 +42,17 @@
public static final String JDK_VERSION = "7";
- private static final SortedSet<String> FixedVersionSet = new TreeSet<String>(){{
+ private static final SortedSet<String> FixedVersionSet = new TreeSet<String>() {{
add(JDK_VERSION);
}};
private static final SortedSet<String> EmptySet = new TreeSet<String>();
public static final Set<String> JDK_MODULES = new TreeSet<String>();
- static{
- for(String module : JDKPackageList.getJDKModuleNames())
+
+ static {
+ for (String module : JDKUtils.getJDKModuleNames())
JDK_MODULES.add(module);
- for(String module : JDKPackageList.getOracleJDKModuleNames())
+ for (String module : JDKUtils.getOracleJDKModuleNames())
JDK_MODULES.add(module);
}
@@ -62,7 +64,7 @@ public JDKRepository() {
protected ArtifactResult getArtifactResultInternal(RepositoryManager manager, Node node) {
return null;
}
-
+
public static class JDKRoot extends DefaultNode implements ContentFinder {
public JDKRoot() {
@@ -73,17 +75,17 @@ public JDKRoot() {
public String getDisplayString() {
return "JDK modules repository";
}
-
+
@Override
public void completeModules(ModuleQuery query, ModuleSearchResult result) {
// abort if not JVM
- if(query.getType() != ModuleQuery.Type.JVM)
+ if (query.getType() != ModuleQuery.Type.JVM)
return;
String name = query.getName();
- if(name == null)
+ if (name == null)
name = "";
- for(String module : JDK_MODULES){
- if(module.startsWith(name))
+ for (String module : JDK_MODULES) {
+ if (module.startsWith(name))
result.addResult(module, doc(module), null, EmptySet, FixedVersionSet);
}
}
@@ -95,11 +97,11 @@ private String doc(String module) {
@Override
public void completeVersions(ModuleVersionQuery query, ModuleVersionResult result) {
// abort if not JVM
- if(query.getType() != ModuleQuery.Type.JVM)
+ if (query.getType() != ModuleQuery.Type.JVM)
return;
- if(query.getName() == null || !JDK_MODULES.contains(query.getName()))
+ if (query.getName() == null || !JDK_MODULES.contains(query.getName()))
return;
- if(query.getVersion() != null && !query.getVersion().equals(JDK_VERSION))
+ if (query.getVersion() != null && !query.getVersion().equals(JDK_VERSION))
return;
final ModuleVersionDetails newVersion = result.addVersion(JDK_VERSION);
newVersion.setDoc(doc(query.getName()));
@@ -109,17 +111,17 @@ public void completeVersions(ModuleVersionQuery query, ModuleVersionResult resul
@Override
public void searchModules(ModuleQuery query, ModuleSearchResult result) {
// abort if not JVM
- if(query.getType() != ModuleQuery.Type.JVM)
+ if (query.getType() != ModuleQuery.Type.JVM)
return;
String name = query.getName();
- if(name == null)
+ if (name == null)
name = "";
name = name.toLowerCase();
boolean stopSearching = false;
int found = 0;
- for(String module : JDK_MODULES){
+ for (String module : JDK_MODULES) {
// does it match?
- if(module.contains(name)){
+ if (module.contains(name)) {
// check if we were already done but were checking for a next results
if (stopSearching) {
// we already found enough results but were checking if there
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit 574dc01

Please sign in to comment.