Mercurial > hg > truffle
comparison graal/com.oracle.max.base/src/com/sun/max/ide/JavaProject.java @ 4184:fa6b78681c54
Added copyright check to the gate.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 03 Jan 2012 12:37:31 +0100 |
parents | bc8527f3071c |
children |
comparison
equal
deleted
inserted
replaced
4183:9e0c1b4cfef5 | 4184:fa6b78681c54 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
33 * {@linkplain Classpath#fromSystem() system class path}. | 33 * {@linkplain Classpath#fromSystem() system class path}. |
34 */ | 34 */ |
35 public final class JavaProject { | 35 public final class JavaProject { |
36 | 36 |
37 /** | 37 /** |
38 * System property name specifying the Maxine workspace directory. | 38 * System property name specifying a directory containing a Mercurial repository. |
39 */ | 39 */ |
40 public static final String MAX_WORKSPACE_PROPERTY = "max.workspace"; | 40 public static final String HG_ROOT_PROPERTY = "hg.root"; |
41 | 41 |
42 /** | 42 /** |
43 * Determines if a given directory is Maxine workspace directory. | 43 * Determines if a given directory contains a Mercurial repository. |
44 * | |
45 * @param dir a directory to test | |
46 * @return {@code true} if {@code dir} is a directory containing a file named "projects.properties" | |
47 */ | 44 */ |
48 public static boolean isWorkspace(File dir) { | 45 public static boolean isHgRoot(File dir) { |
49 return new File(dir, "projects.properties").exists(); | 46 return new File(dir, ".hg").isDirectory(); |
50 } | 47 } |
51 | 48 |
52 private JavaProject() { | 49 private JavaProject() { |
53 } | 50 } |
54 | 51 |
86 } | 83 } |
87 } | 84 } |
88 return new Classpath(classPathEntries); | 85 return new Classpath(classPathEntries); |
89 } | 86 } |
90 | 87 |
91 static class WorkspaceFinder extends ClasspathTraversal { | 88 static class HgRootFinder extends ClasspathTraversal { |
92 | 89 |
93 File workspace; | 90 File hgRoot; |
94 File project; | 91 File project; |
95 | 92 |
96 | 93 |
97 boolean deriveWorkspace(File start) { | 94 boolean deriveHgRoot(File start) { |
98 File dir = start; | 95 File dir = start; |
99 File child = null; | 96 File child = null; |
100 while (dir != null) { | 97 while (dir != null) { |
101 if (isWorkspace(dir)) { | 98 if (isHgRoot(dir)) { |
102 workspace = dir; | 99 hgRoot = dir; |
103 project = child; | 100 project = child; |
104 return true; | 101 return true; |
105 } | 102 } |
106 child = dir; | 103 child = dir; |
107 dir = dir.getParentFile(); | 104 dir = dir.getParentFile(); |
111 | 108 |
112 @Override | 109 @Override |
113 protected boolean visitFile(File parent, String resource) { | 110 protected boolean visitFile(File parent, String resource) { |
114 String classFile = JavaProject.class.getName().replace('.', File.separatorChar) + ".class"; | 111 String classFile = JavaProject.class.getName().replace('.', File.separatorChar) + ".class"; |
115 if (resource.equals(classFile)) { | 112 if (resource.equals(classFile)) { |
116 if (deriveWorkspace(parent)) { | 113 if (deriveHgRoot(parent)) { |
117 return false; | 114 return false; |
118 } | 115 } |
119 } | 116 } |
120 return true; | 117 return true; |
121 } | 118 } |
122 @Override | 119 @Override |
123 protected boolean visitArchiveEntry(java.util.zip.ZipFile archive, java.util.zip.ZipEntry resource) { | 120 protected boolean visitArchiveEntry(java.util.zip.ZipFile archive, java.util.zip.ZipEntry resource) { |
124 String classFile = JavaProject.class.getName().replace('.', File.separatorChar) + ".class"; | 121 String classFile = JavaProject.class.getName().replace('.', File.separatorChar) + ".class"; |
125 if (resource.equals(classFile)) { | 122 if (resource.equals(classFile)) { |
126 File archiveFile = new File(archive.getName()); | 123 File archiveFile = new File(archive.getName()); |
127 if (deriveWorkspace(archiveFile)) { | 124 if (deriveHgRoot(archiveFile)) { |
128 return false; | 125 return false; |
129 } | 126 } |
130 } | 127 } |
131 return true; | 128 return true; |
132 } | 129 } |
133 } | 130 } |
134 | 131 |
135 /** | 132 /** |
136 * Gets Maxine workspace directory (i.e. the parent of all the {@linkplain #WORKSPACE_PROJECTS representative project directories}). | 133 * Gets the directory containing a Mercurial repository based on the {@value JavaProject#HG_ROOT_PROPERTY} |
137 * This can be specified explicitly with the {@value JavaProject#MAX_WORKSPACE_PROPERTY} | 134 * if it exists otherwise from the {@linkplain Classpath#fromSystem() system class path}. |
138 * or is derived from the {@linkplain Classpath#fromSystem() system class path}. | |
139 * | |
140 * @return the Maxine workspace directory | |
141 */ | 135 */ |
142 public static File findWorkspaceDirectory() { | 136 public static File findHgRoot() { |
143 final String prop = System.getProperty(JavaProject.MAX_WORKSPACE_PROPERTY); | 137 final String prop = System.getProperty(JavaProject.HG_ROOT_PROPERTY); |
144 if (prop != null) { | 138 if (prop != null) { |
145 File dir = new File(prop); | 139 File dir = new File(prop); |
146 ProgramError.check(isWorkspace(dir), prop + " is not a Maxine workspace directory"); | 140 ProgramError.check(isHgRoot(dir), prop + " does not contain a Mercurial repository"); |
147 return dir; | 141 return dir; |
148 } | 142 } |
149 WorkspaceFinder finder = new WorkspaceFinder(); | 143 HgRootFinder finder = new HgRootFinder(); |
150 finder.run(Classpath.fromSystem()); | 144 finder.run(Classpath.fromSystem()); |
151 ProgramError.check(finder.workspace != null, "failed to find the Maxine workspace directory"); | 145 ProgramError.check(finder.hgRoot != null, "failed to find a directory containing a Mercurial repository"); |
152 return finder.workspace; | 146 return finder.hgRoot; |
153 } | 147 } |
154 | 148 |
155 /** | 149 /** |
156 * Gets the paths on which all the Java source files for a Java project can be found. | 150 * Gets the paths on which all the Java source files for a Java project can be found. |
157 * | 151 * |
162 */ | 156 */ |
163 public static Classpath getSourcePath(Class projClass, boolean includeDependencies) { | 157 public static Classpath getSourcePath(Class projClass, boolean includeDependencies) { |
164 final Classpath classPath = getClassPath(projClass, includeDependencies); | 158 final Classpath classPath = getClassPath(projClass, includeDependencies); |
165 final List<String> sourcePath = new LinkedList<>(); | 159 final List<String> sourcePath = new LinkedList<>(); |
166 for (Entry entry : classPath.entries()) { | 160 for (Entry entry : classPath.entries()) { |
167 WorkspaceFinder finder = new WorkspaceFinder(); | 161 HgRootFinder finder = new HgRootFinder(); |
168 finder.deriveWorkspace(entry.file()); | 162 finder.deriveHgRoot(entry.file()); |
169 final File projectDirectory = finder.project; | 163 final File projectDirectory = finder.project; |
170 if (projectDirectory != null) { | 164 if (projectDirectory != null) { |
171 final File srcDirectory = new File(projectDirectory, SOURCE_DIRECTORY_NAME); | 165 final File srcDirectory = new File(projectDirectory, SOURCE_DIRECTORY_NAME); |
172 if (srcDirectory.exists() && srcDirectory.isDirectory()) { | 166 if (srcDirectory.exists() && srcDirectory.isDirectory()) { |
173 sourcePath.add(srcDirectory.getPath()); | 167 sourcePath.add(srcDirectory.getPath()); |