├── .gitignore ├── README.md ├── build.gradle ├── buildSrc ├── build.gradle └── src │ └── main │ ├── groovy │ └── org │ │ └── netbeans │ │ └── gradle │ │ └── build │ │ ├── NbmDependencyVerifierPlugin.java │ │ └── ZippedJarsFileCollection.java │ └── resources │ └── META-INF │ └── gradle-plugins │ └── nbm-dependency-verifier.properties ├── gradle ├── compiler-settings.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── netbeans-gradle-javaee-models ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── netbeans │ │ └── gradle │ │ └── javaee │ │ └── models │ │ ├── EnumProjectInfoBuilderRef.java │ │ ├── GradleEEModelBuilders.java │ │ ├── NbJpaModel.java │ │ └── NbWebModel.java │ └── modelBuilders │ └── groovy │ └── org │ └── netbeans │ └── gradle │ └── javaee │ └── models │ ├── NbJpaModelBuilder.java │ └── NbWebModelBuilder.java ├── netbeans-gradle-javaee-plugin ├── build.gradle ├── license.txt └── src │ └── main │ ├── java │ └── org │ │ └── netbeans │ │ └── gradle │ │ └── javaee │ │ ├── jpa │ │ ├── JpaModuleExtension.java │ │ ├── JpaModuleExtensionDef.java │ │ └── verification │ │ │ ├── GradlePersistenceScopeImpl.java │ │ │ ├── GradlePersistenceScopesImpl.java │ │ │ └── GradlePersistenceScopesProvider.java │ │ └── web │ │ ├── GradleWebModuleImpl.java │ │ ├── GradleWebModuleProvider.java │ │ ├── ModelReloadListener.java │ │ ├── WebModuleExtension.java │ │ ├── WebModuleExtensionDef.java │ │ ├── nodes │ │ └── WebModuleExtensionNodes.java │ │ └── sources │ │ └── GradleWebProjectSources.java │ ├── nbm │ └── manifest.mf │ └── resources │ └── org │ └── netbeans │ └── gradle │ └── javaee │ └── plugin │ └── Bundle.properties └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | /*/nb-configuration.xml 2 | /nbproject/ 3 | /*/nbproject/ 4 | /*/target/ 5 | /*/build/ 6 | /netbeans-gradle-javaee-models/gradle-api/ 7 | .gradle/ 8 | /.nb-gradle-properties 9 | .nb-gradle/ 10 | 11 | # Directories left from old Ant project 12 | /build/ 13 | /nbproject/private/ 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | netbeans-gradle-javaee-project 2 | ============================== 3 | 4 | A NetBeans plugin to provide Java EE support to Gradle projects. This builds on top of the standard Gradle plugin for NetBeans, but contains dependencies on the Java EE NetBeans modules that might be restrictive for Gradle projects that don't use Java EE. 5 | 6 | I created the plugin to address the issues I came across writing enterprise applications using Gradle. I am doing this in my spare time, so I can't promise a rapid response. But, I'm happy to accept pull requests if you want to chip in. 7 | 8 | Feel free to add issues for important items you think should be addressed. 9 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | group = 'com.github.hildo' 3 | version = '1.0.3' 4 | 5 | ext { 6 | nbGradleVersion = '1.4.0' 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /buildSrc/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | def javaVersion = 1.7 4 | sourceCompatibility = javaVersion 5 | targetCompatibility = javaVersion 6 | 7 | def compileTasks = [compileJava, compileTestJava, compileGroovy, compileTestGroovy] 8 | compileTasks*.options*.encoding = 'UTF-8' 9 | 10 | dependencies { 11 | compile gradleApi() 12 | compile localGroovy() 13 | compile 'org.gradle:gradle-tooling-api:1.11' 14 | compile 'org.codehaus.mojo:nbm-maven-harness:7.4' 15 | compile 'cz.kubacki.gradle.plugins:gradle-nbm-plugin:1.15.0' 16 | compile 'org.apache.maven.shared:maven-dependency-analyzer:1.6' 17 | runtime 'org.slf4j:slf4j-simple:1.7.5' 18 | } 19 | 20 | repositories { 21 | mavenCentral() 22 | jcenter() 23 | maven { 24 | url 'http://repo.gradle.org/gradle/libs-releases-local' 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/netbeans/gradle/build/NbmDependencyVerifierPlugin.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.build; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.MalformedURLException; 6 | import java.net.URL; 7 | import java.net.URLClassLoader; 8 | import java.nio.file.FileSystem; 9 | import java.nio.file.FileSystems; 10 | import java.nio.file.FileVisitResult; 11 | import java.nio.file.FileVisitor; 12 | import java.nio.file.Files; 13 | import java.nio.file.Path; 14 | import java.nio.file.attribute.BasicFileAttributes; 15 | import java.security.CodeSource; 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.Collection; 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.HashSet; 22 | import java.util.List; 23 | import java.util.Locale; 24 | import java.util.Map; 25 | import java.util.Objects; 26 | import java.util.Set; 27 | import java.util.TreeSet; 28 | 29 | import org.apache.maven.shared.dependency.analyzer.asm.ASMDependencyAnalyzer; 30 | import org.gradle.api.Action; 31 | import org.gradle.api.Plugin; 32 | import org.gradle.api.Project; 33 | import org.gradle.api.Task; 34 | import org.gradle.api.artifacts.Configuration; 35 | import org.gradle.api.artifacts.Dependency; 36 | import org.gradle.api.artifacts.ResolvedArtifact; 37 | import org.gradle.api.artifacts.ResolvedDependency; 38 | import org.gradle.api.artifacts.component.ComponentIdentifier; 39 | import org.gradle.api.artifacts.component.ModuleComponentIdentifier; 40 | import org.gradle.api.artifacts.dsl.DependencyHandler; 41 | import org.gradle.api.file.FileCollection; 42 | import org.gradle.jvm.tasks.Jar; 43 | 44 | public final class NbmDependencyVerifierPlugin implements Plugin { 45 | private static final List UNCHECKED = Arrays.asList( 46 | new VersionlessArtifactId("com.github.kelemen", "netbeans-gradle-default-models")); 47 | 48 | @Override 49 | public void apply(final Project project) { 50 | Task verifyTask = project.task("verifyModuleDependencies"); 51 | verifyTask.dependsOn("jar"); 52 | project.getTasks().getByName("check").dependsOn(verifyTask); 53 | 54 | verifyTask.doLast(new Action() { 55 | @Override 56 | public void execute(Task task) { 57 | Jar jar = (Jar)project.getTasks().getByName("jar"); 58 | verifyDependencies(project, jar.getArchivePath()); 59 | } 60 | }); 61 | } 62 | 63 | private void verifyDependencies(Project project, File jarPath) { 64 | try { 65 | verifyDependencies0(project, jarPath); 66 | } catch (IOException ex) { 67 | throw new RuntimeException(ex); 68 | } 69 | } 70 | 71 | private static Set getOwnClasses(File jarPath) throws IOException { 72 | final Set result = new HashSet<>(); 73 | try (FileSystem fs = FileSystems.newFileSystem(jarPath.toPath(), null)) { 74 | for (Path root: fs.getRootDirectories()) { 75 | Files.walkFileTree(root, new FileVisitor() { 76 | @Override 77 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { 78 | return FileVisitResult.CONTINUE; 79 | } 80 | 81 | @Override 82 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { 83 | String extension = ".class"; 84 | String path = file.toString(); 85 | if (path.toLowerCase(Locale.ROOT).endsWith(extension)) { 86 | String extensionLessPath = path.substring(0, path.length() - extension.length()); 87 | String className = removeStartingChars(extensionLessPath.replace('/', '.'), '.'); 88 | result.add(className); 89 | } 90 | return FileVisitResult.CONTINUE; 91 | } 92 | 93 | @Override 94 | public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { 95 | return FileVisitResult.CONTINUE; 96 | } 97 | 98 | @Override 99 | public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { 100 | return FileVisitResult.CONTINUE; 101 | } 102 | }); 103 | } 104 | } 105 | return result; 106 | } 107 | 108 | private static String removeStartingChars(String str, char ch) { 109 | for (int i = 0; i < str.length(); i++) { 110 | if (str.charAt(i) != ch) { 111 | return str.substring(i); 112 | } 113 | } 114 | return ""; 115 | } 116 | 117 | private void verifyDependencies0(Project project, File jarPath) throws IOException { 118 | Set ownClasses = getOwnClasses(jarPath); 119 | Set classes = getClasses(jarPath); 120 | 121 | Configuration providedCompile = project.getConfigurations().getByName("providedCompile"); 122 | Configuration uncheckedDependencies = getUncheckedDependencies(project, providedCompile); 123 | 124 | FileCollection compile = project.getConfigurations().getByName("compile") 125 | .minus(providedCompile) 126 | .plus(uncheckedDependencies); 127 | 128 | Map missing = new HashMap<>(); 129 | try (URLClassLoader accessibleLoader = urlClassLoader(getFirstLevelUrls(providedCompile)); 130 | URLClassLoader allClassLoader = urlClassLoader(getAllUrls(providedCompile)); 131 | URLClassLoader compileLoader = urlClassLoader(getAllUrls(compile))) { 132 | 133 | for (String className: classes) { 134 | if (!ownClasses.contains(className) && !hasClass(accessibleLoader, className)) { 135 | if (hasClass(allClassLoader, className) && !hasClass(compileLoader, className)) { 136 | URL owner = tryGetClassOwner(allClassLoader, className); 137 | missing.put(className, owner != null ? owner.toString() : "unknown"); 138 | } 139 | } 140 | } 141 | } 142 | 143 | if (!missing.isEmpty()) { 144 | failWithMissingDependency(missing); 145 | } 146 | } 147 | 148 | private static boolean contains(ModuleComponentIdentifier dependency, Collection collection) { 149 | VersionlessArtifactId searched = new VersionlessArtifactId(dependency.getGroup(), dependency.getModule()); 150 | return collection.contains(searched); 151 | } 152 | 153 | private static Configuration getUncheckedDependencies(Project project, Configuration providedCompile) { 154 | List resultIds = new ArrayList<>(); 155 | for (ResolvedArtifact dependency : providedCompile.getResolvedConfiguration().getResolvedArtifacts()) { 156 | ModuleComponentIdentifier id = tryGetId(dependency); 157 | if (id != null) { 158 | if (contains(id, UNCHECKED)) { 159 | resultIds.add(id); 160 | } 161 | } 162 | } 163 | 164 | DependencyHandler dependencies = project.getDependencies(); 165 | List result = new ArrayList<>(resultIds.size()); 166 | for (ModuleComponentIdentifier id : resultIds) { 167 | Dependency dependency = dependencies.module(id.getGroup() + ":" + id.getModule() + ":" + id.getVersion()); 168 | result.add(dependency); 169 | } 170 | return project.getConfigurations().detachedConfiguration(result.toArray(new Dependency[0])); 171 | } 172 | 173 | private static ModuleComponentIdentifier tryGetId(ResolvedArtifact dependency) { 174 | ComponentIdentifier id = dependency.getId().getComponentIdentifier(); 175 | return id instanceof ModuleComponentIdentifier 176 | ? (ModuleComponentIdentifier) id 177 | : null; 178 | } 179 | 180 | private static URLClassLoader urlClassLoader(List urls) { 181 | return new URLClassLoader(urls.toArray(new URL[urls.size()]), ClassLoader.getSystemClassLoader()); 182 | } 183 | 184 | private static URL tryGetClassOwner(ClassLoader loader, String className) { 185 | Class cl; 186 | try { 187 | cl = loader.loadClass(className); 188 | } catch (ClassNotFoundException ex) { 189 | return null; 190 | } 191 | 192 | CodeSource codeSource = cl.getProtectionDomain().getCodeSource(); 193 | if (codeSource == null) { 194 | return null; 195 | } 196 | return codeSource.getLocation(); 197 | } 198 | 199 | private static boolean hasClass(ClassLoader loader, String className) { 200 | return loader.getResource(className.replace('.', '/') + ".class") != null; 201 | } 202 | 203 | private void failWithMissingDependency(Map missing) { 204 | List sortedMissing = new ArrayList<>(missing.keySet()); 205 | Collections.sort(sortedMissing); 206 | 207 | StringBuilder message = new StringBuilder(); 208 | message.append("The following classes are not in a directly declared dependency:"); 209 | for (String dependency: sortedMissing) { 210 | message.append("\n- "); 211 | message.append(dependency); 212 | message.append(" but was found in "); 213 | message.append(missing.get(dependency)); 214 | } 215 | message.append("\n\nRequired explicit dependencies:"); 216 | 217 | Set result = new TreeSet<>(missing.values()); 218 | 219 | for (String owner: result) { 220 | message.append("\n- "); 221 | message.append(owner); 222 | } 223 | message.append("\n"); 224 | 225 | throw new IllegalStateException(message.toString()); 226 | } 227 | 228 | private List getAllUrls(FileCollection config) throws MalformedURLException { 229 | List result = new ArrayList<>(); 230 | for (File dep: config.getFiles()) { 231 | result.add(dep.toURI().toURL()); 232 | } 233 | return result; 234 | } 235 | 236 | private List getFirstLevelUrls(Configuration config) throws MalformedURLException { 237 | List result = new ArrayList<>(); 238 | for (ResolvedDependency dep: config.getResolvedConfiguration().getFirstLevelModuleDependencies()) { 239 | for (ResolvedArtifact art: dep.getModuleArtifacts()) { 240 | result.add(art.getFile().toURI().toURL()); 241 | } 242 | } 243 | return result; 244 | } 245 | 246 | private Set getClasses(File jarPath) throws IOException { 247 | ASMDependencyAnalyzer analizer = new ASMDependencyAnalyzer(); 248 | return analizer.analyze(jarPath.toURI().toURL()); 249 | } 250 | 251 | private static final class VersionlessArtifactId { 252 | private final String group; 253 | private final String name; 254 | 255 | public VersionlessArtifactId(String group, String name) { 256 | this.group = group; 257 | this.name = name; 258 | } 259 | 260 | @Override 261 | public int hashCode() { 262 | int hash = 5; 263 | hash = 89 * hash + Objects.hashCode(group); 264 | hash = 89 * hash + Objects.hashCode(name); 265 | return hash; 266 | } 267 | 268 | @Override 269 | public boolean equals(Object obj) { 270 | if (this == obj) return true; 271 | if (obj == null) return false; 272 | if (getClass() != obj.getClass()) return false; 273 | 274 | final VersionlessArtifactId other = (VersionlessArtifactId) obj; 275 | return Objects.equals(this.group, other.group) 276 | && Objects.equals(this.name, other.name); 277 | } 278 | } 279 | } 280 | -------------------------------------------------------------------------------- /buildSrc/src/main/groovy/org/netbeans/gradle/build/ZippedJarsFileCollection.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.build; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.nio.charset.Charset; 7 | import java.nio.file.FileSystem; 8 | import java.nio.file.FileSystems; 9 | import java.nio.file.FileVisitResult; 10 | import java.nio.file.FileVisitor; 11 | import java.nio.file.Files; 12 | import java.nio.file.Path; 13 | import java.nio.file.StandardCopyOption; 14 | import java.nio.file.attribute.BasicFileAttributes; 15 | import java.util.ArrayList; 16 | import java.util.Collections; 17 | import java.util.List; 18 | import java.util.Locale; 19 | import java.util.Set; 20 | import org.gradle.api.Project; 21 | import org.gradle.api.artifacts.Configuration; 22 | import org.gradle.api.artifacts.Dependency; 23 | import org.gradle.api.internal.file.AbstractFileCollection; 24 | 25 | public final class ZippedJarsFileCollection extends AbstractFileCollection { 26 | private final Charset UTF8 = Charset.forName("UTF-8"); 27 | 28 | private final Project project; 29 | private final String dependencyNotation; 30 | private final Configuration dependencyContainer; 31 | private final Path unzipDir; 32 | private final List subDirPath; 33 | 34 | public ZippedJarsFileCollection( 35 | Project project, 36 | String dependencyNotation, 37 | List unzipPath, 38 | List subDirPath) { 39 | this.project = project; 40 | Dependency dependency = project.getDependencies().create(dependencyNotation); 41 | this.dependencyContainer = project.getConfigurations().detachedConfiguration(dependency); 42 | this.unzipDir = resolve(project.getProjectDir().toPath(), unzipPath); 43 | this.dependencyNotation = dependencyNotation; 44 | this.subDirPath = new ArrayList<>(subDirPath); 45 | } 46 | 47 | private static Path resolve(Path dir, List subDirs) { 48 | Path result = dir; 49 | for (String subDir: subDirs) { 50 | result = result.resolve(subDir); 51 | } 52 | return result; 53 | } 54 | 55 | private Path getExtractedFilesDir() { 56 | return unzipDir.resolve("files"); 57 | } 58 | 59 | private Path getExtractedMarker() { 60 | return unzipDir.resolve("EXTRACTED"); 61 | } 62 | 63 | private void extractSafe() { 64 | try { 65 | extract(); 66 | } catch (IOException ex) { 67 | throw new RuntimeException(ex); 68 | } 69 | } 70 | 71 | private static void safeCopy(Path src, Path dest) throws IOException { 72 | try (InputStream input = Files.newInputStream(src)) { 73 | Files.copy(input, dest, StandardCopyOption.REPLACE_EXISTING); 74 | } 75 | } 76 | 77 | private void markExtracted() throws IOException { 78 | Path extractedMarker = getExtractedMarker(); 79 | List lines = Collections.singletonList(dependencyNotation); 80 | Files.write(extractedMarker, lines, UTF8); 81 | } 82 | 83 | private boolean isExtracted() throws IOException { 84 | Path extractedMarker = getExtractedMarker(); 85 | if (!Files.isRegularFile(extractedMarker)) { 86 | return false; 87 | } 88 | 89 | List lines = Files.readAllLines(extractedMarker, UTF8); 90 | if (lines.isEmpty()) { 91 | return false; 92 | } 93 | 94 | return dependencyNotation.equals(lines.get(0)); 95 | } 96 | 97 | private void tryDeleteDirectory(Path directory) { 98 | project.delete(directory.toFile()); 99 | } 100 | 101 | private void copyDir(final Path srcDir, final Path destDir) throws IOException { 102 | tryDeleteDirectory(destDir); 103 | Files.createDirectories(destDir); 104 | 105 | Files.walkFileTree(srcDir, new FileVisitor() { 106 | private Path currentDir = destDir; 107 | 108 | @Override 109 | public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { 110 | if (!srcDir.equals(dir)) { 111 | currentDir = currentDir.resolve(dir.getFileName().toString()); 112 | Files.createDirectory(currentDir); 113 | } 114 | return FileVisitResult.CONTINUE; 115 | } 116 | 117 | @Override 118 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { 119 | String fileName = file.getFileName().toString(); 120 | String normName = fileName.toLowerCase(Locale.ROOT); 121 | if (normName.endsWith(".jar")) { 122 | safeCopy(file, currentDir.resolve(fileName)); 123 | } 124 | return FileVisitResult.CONTINUE; 125 | } 126 | 127 | @Override 128 | public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { 129 | return FileVisitResult.CONTINUE; 130 | } 131 | 132 | @Override 133 | public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { 134 | currentDir = currentDir != null ? currentDir.getParent() : null; 135 | return FileVisitResult.CONTINUE; 136 | } 137 | }); 138 | } 139 | 140 | private void extract() throws IOException { 141 | if (isExtracted()) { 142 | return; 143 | } 144 | 145 | Path zipFile = dependencyContainer.getSingleFile().toPath(); 146 | FileSystem zipFS = FileSystems.newFileSystem(zipFile, null); 147 | Path root = zipFS.getRootDirectories().iterator().next(); 148 | Path libDir = resolve(root, subDirPath); 149 | 150 | copyDir(libDir, getExtractedFilesDir()); 151 | 152 | markExtracted(); 153 | } 154 | 155 | @Override 156 | public String getDisplayName() { 157 | return "UnZip: " + dependencyNotation; 158 | } 159 | 160 | @Override 161 | public Set getFiles() { 162 | extractSafe(); 163 | 164 | return project.fileTree(getExtractedFilesDir().toFile()).getFiles(); 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /buildSrc/src/main/resources/META-INF/gradle-plugins/nbm-dependency-verifier.properties: -------------------------------------------------------------------------------- 1 | implementation-class=org.netbeans.gradle.build.NbmDependencyVerifierPlugin 2 | 3 | -------------------------------------------------------------------------------- /gradle/compiler-settings.gradle: -------------------------------------------------------------------------------- 1 | import java.nio.file.* 2 | 3 | ext.configureJavaCompilers = { int javaVersion -> 4 | def requiredVersion = JavaVersion.toVersion("1.${javaVersion}"); 5 | 6 | sourceCompatibility = requiredVersion 7 | targetCompatibility = requiredVersion 8 | 9 | def compileTasks = tasks.withType(JavaCompile); 10 | def compilerOptions = compileTasks*.options; 11 | compilerOptions*.encoding = 'UTF-8'; 12 | compilerOptions*.compilerArgs = ['-Xlint']; 13 | 14 | if (JavaVersion.current() != requiredVersion) { 15 | String explicitJavaCompiler = tryGetExplicitJdkCompiler(project, javaVersion); 16 | if (explicitJavaCompiler != null) { 17 | compilerOptions*.fork = true; 18 | compilerOptions*.forkOptions*.executable = explicitJavaCompiler; 19 | } 20 | else { 21 | compileTasks*.doFirst { 22 | String jdkProperty = getJdkPropertyName(javaVersion); 23 | logger.warn "Warning: ${jdkProperty} property is missing and not compiling with Java ${requiredVersion}. Using ${JavaVersion.current()}"; 24 | } 25 | } 26 | } 27 | } 28 | 29 | ext.findToolsJar = { int javaVersion -> 30 | String explicitToolsJarProperty = "jdk${javaVersion}ToolsJar"; 31 | if (project.hasProperty(explicitToolsJarProperty)) { 32 | return new File(project.property(explicitToolsJarProperty).toString().trim()); 33 | } 34 | 35 | String foundToolsJar = null; 36 | String explicitJavaCompiler = tryGetExplicitJdkCompiler(project, javaVersion); 37 | if (explicitJavaCompiler != null) { 38 | foundToolsJar = extractToolsJarFromCompiler(explicitJavaCompiler); 39 | } 40 | 41 | if (foundToolsJar == null) { 42 | String javaHome = System.getProperty('java.home'); 43 | foundToolsJar = extractToolsJarFromJavaHome(javaHome); 44 | } 45 | 46 | if (foundToolsJar == null) { 47 | throw new IllegalStateException("Unable to find the JDK's tools.jar."); 48 | } 49 | 50 | return new File(foundToolsJar); 51 | } 52 | 53 | String extractToolsJarFromJDKHome(Path jdkHome) { 54 | Path toolsJar = jdkHome?.resolve('lib')?.resolve('tools.jar'); 55 | if (toolsJar == null) { 56 | return null; 57 | } 58 | 59 | if (!Files.isRegularFile(toolsJar)) { 60 | return null; 61 | } 62 | 63 | return toolsJar.toString(); 64 | } 65 | 66 | String extractToolsJarFromJavaHome(String javaHome) { 67 | Path javaHomePath = javaHome != null ? Paths.get(javaHome) : null; 68 | Path jdkHome = javaHomePath?.parent; 69 | return extractToolsJarFromJDKHome(jdkHome); 70 | } 71 | 72 | String extractToolsJarFromCompiler(String javac) { 73 | Path javacPath = javac != null ? Paths.get(javac) : null; 74 | Path jdkHome = javacPath?.parent.parent; 75 | return extractToolsJarFromJDKHome(jdkHome); 76 | } 77 | 78 | String getJdkPropertyName(int javaVersion) { 79 | return "jdk${javaVersion}Compiler"; 80 | } 81 | 82 | String tryGetExplicitJdkCompiler(def project, int javaVersion) { 83 | String jdkProperty = getJdkPropertyName(javaVersion); 84 | if (project.hasProperty(jdkProperty)) { 85 | return project.property(jdkProperty).toString().trim(); 86 | } 87 | else { 88 | return null; 89 | } 90 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hildo/netbeans-gradle-javaee-project/4f49f36aebcd668f116df7c5df87f70778558733/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Aug 15 20:51:00 CEST 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=http\://services.gradle.org/distributions/gradle-2.13-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'groovy' 2 | 3 | String gradleVersion = '2.13' 4 | 5 | ext.scriptFile = { String fileName -> 6 | return new File(new File(rootDir, 'gradle'), fileName) 7 | } 8 | 9 | apply from: scriptFile('compiler-settings.gradle') 10 | 11 | repositories { 12 | mavenCentral() 13 | 14 | maven { 15 | url 'http://repo.gradle.org/gradle/libs-releases-local' 16 | } 17 | 18 | maven { 19 | url 'http://repo.gradle.org/gradle/libs-snapshots-local' 20 | } 21 | 22 | maven { url 'http://dl.bintray.com/kelemen/maven' } 23 | 24 | ivy { 25 | // This "repository" was added only as a hack to download 26 | // the Gradle distribution at http://services.gradle.org/distributions/gradle-1.8-bin.zip 27 | url 'http://services.gradle.org' 28 | layout 'pattern', { 29 | artifact '[organisation]/[artifact]-[revision].[ext]' 30 | } 31 | } 32 | } 33 | 34 | sourceSets { 35 | main { 36 | groovy.srcDirs = [] 37 | } 38 | modelBuilders { 39 | compileClasspath += main.output 40 | java.srcDirs = [] 41 | } 42 | test { 43 | groovy.srcDirs = [] 44 | 45 | compileClasspath += configurations.modelBuildersCompile 46 | runtimeClasspath -= main.output 47 | runtimeClasspath += files(jar.archivePath) 48 | } 49 | } 50 | 51 | configurations { 52 | modelBuildersCompile.extendsFrom compile 53 | modelBuildersCompile.exclude module: 'gradle-tooling-api' 54 | } 55 | 56 | configureJavaCompilers(7) 57 | 58 | compileTestJava.dependsOn(jar) 59 | 60 | jar { 61 | from sourceSets.modelBuilders.output 62 | ext { 63 | netBeansSourceSets = [sourceSets.main, sourceSets.modelBuilders] 64 | } 65 | } 66 | 67 | task sourcesJar(type: Jar, dependsOn: classes, description: 'Creates a jar from the source files.') { 68 | classifier = 'sources' 69 | from sourceSets.main.allSource 70 | from sourceSets.modelBuilders.allSource 71 | } 72 | 73 | artifacts { 74 | archives jar 75 | archives sourcesJar 76 | } 77 | 78 | dependencies { 79 | compileOnly "com.github.kelemen:netbeans-gradle-plugin:${nbGradleVersion}" 80 | modelBuildersCompileOnly "com.github.kelemen:netbeans-gradle-plugin:${nbGradleVersion}" 81 | 82 | modelBuildersCompileOnly group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.8.6' 83 | 84 | def gradleApiDependency = new org.netbeans.gradle.build.ZippedJarsFileCollection( 85 | project, 86 | 'distributions:gradle:1.8-bin@zip', 87 | ['gradle-api'], 88 | ['gradle-1.8', 'lib'] 89 | ) 90 | modelBuildersCompileOnly gradleApiDependency 91 | 92 | testCompile group: 'junit', name: 'junit', version: '4.11' 93 | testCompile group: 'org.mockito', name: 'mockito-core', version: '1.9.5' 94 | } 95 | 96 | test.systemProperty 'TESTED_GRADLE_DAEMON_VERSION', gradleVersion 97 | 98 | afterEvaluate { 99 | System.setProperty('line.separator', '\n') 100 | } 101 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/src/main/java/org/netbeans/gradle/javaee/models/EnumProjectInfoBuilderRef.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.javaee.models; 2 | 3 | import java.io.InvalidObjectException; 4 | import java.io.ObjectInputStream; 5 | import java.io.ObjectStreamException; 6 | import java.io.Serializable; 7 | import java.util.Arrays; 8 | import java.util.concurrent.atomic.AtomicReference; 9 | 10 | import org.netbeans.gradle.model.api.ProjectInfoBuilder2; 11 | 12 | public final class EnumProjectInfoBuilderRef implements ProjectInfoBuilder2 { 13 | private static final long serialVersionUID = 1L; 14 | 15 | private final Class modelType; 16 | private final String wrappedTypeName; 17 | private final String wrappedConstName; 18 | 19 | private final AtomicReference> wrappedRef; 20 | 21 | public EnumProjectInfoBuilderRef( 22 | Class modelType, 23 | String wrappedTypeName) { 24 | if (modelType == null) throw new NullPointerException("modelType"); 25 | if (wrappedTypeName == null) throw new NullPointerException("wrappedTypeName"); 26 | 27 | this.modelType = modelType; 28 | this.wrappedTypeName = updateTypeName(modelType, wrappedTypeName); 29 | this.wrappedConstName = null; 30 | this.wrappedRef = new AtomicReference<>(null); 31 | } 32 | 33 | public EnumProjectInfoBuilderRef( 34 | Class modelType, 35 | String wrappedTypeName, 36 | String wrappedConstName) { 37 | if (modelType == null) throw new NullPointerException("modelType"); 38 | if (wrappedTypeName == null) throw new NullPointerException("wrappedTypeName"); 39 | if (wrappedConstName == null) throw new NullPointerException("wrappedConstName"); 40 | 41 | this.modelType = modelType; 42 | this.wrappedTypeName = updateTypeName(modelType, wrappedTypeName); 43 | this.wrappedConstName = wrappedConstName; 44 | this.wrappedRef = new AtomicReference<>(null); 45 | } 46 | 47 | private static String updateTypeName(Class defaultPackage, String typeName) { 48 | if (typeName.indexOf('.') >= 0) { 49 | return typeName; 50 | } 51 | return defaultPackage.getPackage().getName() + "." + typeName; 52 | } 53 | 54 | private static Object unsafeEnumValueOf(Class type, String constName) { 55 | Object[] enumConsts = type.getEnumConstants(); 56 | if (constName != null) { 57 | for (Object enumConst: enumConsts) { 58 | String name = ((Enum)enumConst).name(); 59 | if (constName.equals(name)) { 60 | return enumConst; 61 | } 62 | } 63 | throw new IllegalStateException("No such enum constant for type " + type.getName() + ": " + constName); 64 | } 65 | else { 66 | if (enumConsts.length != 1) { 67 | throw new IllegalStateException("Cannot determine which enum const must be used: " + Arrays.asList(enumConsts)); 68 | } 69 | return enumConsts[0]; 70 | } 71 | } 72 | 73 | private ProjectInfoBuilder2 createWrapped() { 74 | try { 75 | return (ProjectInfoBuilder2)unsafeEnumValueOf(Class.forName(wrappedTypeName), wrappedConstName); 76 | } catch (Exception ex) { 77 | if (ex instanceof RuntimeException) { 78 | throw (RuntimeException)ex; 79 | } 80 | throw new RuntimeException(ex); 81 | } 82 | } 83 | 84 | private ProjectInfoBuilder2 getWrapped() { 85 | ProjectInfoBuilder2 result = wrappedRef.get(); 86 | if (result == null) { 87 | result = createWrapped(); 88 | if (!wrappedRef.compareAndSet(null, result)) { 89 | result = wrappedRef.get(); 90 | } 91 | } 92 | return result; 93 | } 94 | 95 | @Override 96 | public T getProjectInfo(Object project) { 97 | Object result = getWrapped().getProjectInfo(project); 98 | return modelType.cast(result); 99 | } 100 | 101 | @Override 102 | public String getName() { 103 | return getWrapped().getName(); 104 | } 105 | 106 | private Object writeReplace() { 107 | return new SerializedFormat(this); 108 | } 109 | 110 | private void readObject(ObjectInputStream stream) throws InvalidObjectException { 111 | throw new InvalidObjectException("Use proxy."); 112 | } 113 | 114 | private static final class SerializedFormat implements Serializable { 115 | private static final long serialVersionUID = 1L; 116 | 117 | private final Class modelType; 118 | private final String wrappedTypeName; 119 | private final String wrappedConstName; 120 | 121 | public SerializedFormat(EnumProjectInfoBuilderRef source) { 122 | this.modelType = source.modelType; 123 | this.wrappedTypeName = source.wrappedTypeName; 124 | this.wrappedConstName = source.wrappedConstName; 125 | } 126 | 127 | private Object readResolve() throws ObjectStreamException { 128 | return wrappedConstName != null 129 | ? new EnumProjectInfoBuilderRef<>(modelType, wrappedTypeName, wrappedConstName) 130 | : new EnumProjectInfoBuilderRef<>(modelType, wrappedTypeName); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/src/main/java/org/netbeans/gradle/javaee/models/GradleEEModelBuilders.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.javaee.models; 2 | 3 | import org.netbeans.gradle.model.api.ProjectInfoBuilder2; 4 | 5 | public final class GradleEEModelBuilders { 6 | public static final ProjectInfoBuilder2 JPA_BUILDER 7 | = new EnumProjectInfoBuilderRef<>(NbJpaModel.class, "NbJpaModelBuilder"); 8 | 9 | public static final ProjectInfoBuilder2 WEB_BUILDER 10 | = new EnumProjectInfoBuilderRef<>(NbWebModel.class, "NbWebModelBuilder"); 11 | 12 | private GradleEEModelBuilders() { 13 | throw new AssertionError(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/src/main/java/org/netbeans/gradle/javaee/models/NbJpaModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.models; 7 | 8 | import java.io.File; 9 | import java.io.Serializable; 10 | 11 | /** 12 | * 13 | * @author ed 14 | */ 15 | public final class NbJpaModel implements Serializable { 16 | private static final long serialVersionUID = 1L; 17 | 18 | private final String persistenceFile; 19 | private final Iterable javaSourceDirs; 20 | 21 | public NbJpaModel(String persistenceFile, Iterable compileClasspath) { 22 | this.persistenceFile = persistenceFile; 23 | this.javaSourceDirs = serializableIterable(compileClasspath); 24 | } 25 | 26 | private Iterable serializableIterable(Iterable iterable) { 27 | java.util.ArrayList returnValue = new java.util.ArrayList<>(); 28 | for (File file : iterable) { 29 | returnValue.add(file); 30 | } 31 | return returnValue; 32 | } 33 | 34 | public String getPersistenceFile() { 35 | return persistenceFile; 36 | } 37 | 38 | public Iterable getJavaSourceDirs() { 39 | return javaSourceDirs; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/src/main/java/org/netbeans/gradle/javaee/models/NbWebModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package org.netbeans.gradle.javaee.models; 8 | 9 | import java.io.Serializable; 10 | 11 | /** 12 | * Handy doco pages for this: 13 | * http://www.gradle.org/docs/current/userguide/war_plugin.html 14 | * http://www.gradle.org/docs/current/dsl/org.gradle.api.plugins.WarPluginConvention.html 15 | * 16 | * @author Ed 17 | */ 18 | public final class NbWebModel implements Serializable { 19 | private static final long serialVersionUID = 2209710889385730864L; 20 | 21 | private final String webAppDir; 22 | private final String deploymentDescName; 23 | 24 | public NbWebModel(String webAppDir, String deploymentDescName) { 25 | this.webAppDir = webAppDir; 26 | this.deploymentDescName = deploymentDescName; 27 | } 28 | 29 | public String getWebAppDir() { 30 | return webAppDir; 31 | } 32 | 33 | public String getDeploymentDescName() { 34 | return deploymentDescName; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/src/modelBuilders/groovy/org/netbeans/gradle/javaee/models/NbJpaModelBuilder.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.javaee.models; 2 | 3 | import java.io.File; 4 | import java.util.Set; 5 | 6 | import org.gradle.api.Project; 7 | import org.gradle.api.file.SourceDirectorySet; 8 | import org.gradle.api.plugins.JavaPluginConvention; 9 | import org.gradle.api.tasks.SourceSet; 10 | import org.jtrim.utils.ExceptionHelper; 11 | import org.netbeans.gradle.model.api.ProjectInfoBuilder2; 12 | 13 | /** 14 | * 15 | * @author ed 16 | */ 17 | enum NbJpaModelBuilder implements ProjectInfoBuilder2{ 18 | INSTANCE; 19 | 20 | @Override 21 | public NbJpaModel getProjectInfo(Object project) { 22 | return getProjectInfo((Project)project); 23 | } 24 | 25 | private NbJpaModel getProjectInfo(Project project) { 26 | NbJpaModel returnValue = null; 27 | try { 28 | Builder builder = new Builder(project); 29 | if (builder.getPersistenceXmlFile() != null) { 30 | returnValue = new NbJpaModel( 31 | builder.getPersistenceXmlFile(), 32 | builder.getJavaSourceDirs() 33 | ); 34 | } 35 | } catch (Exception ex) { 36 | throw ExceptionHelper.throwUnchecked(ex); 37 | } 38 | return returnValue; 39 | } 40 | 41 | @Override 42 | public String getName() { 43 | return getClass().getName(); 44 | } 45 | 46 | private static class Builder { 47 | private final Project project; 48 | //private final SourceSetMethods sourceSetMethods; 49 | //private final SourceDirectorySetMethods sourceDirectorySetMethods; 50 | private String persistenceXmlFile; 51 | private Iterable javaSourceDirs; 52 | 53 | Builder(Project project) throws Exception { 54 | this.project = project; 55 | init(); 56 | } 57 | 58 | String getPersistenceXmlFile() { 59 | return persistenceXmlFile; 60 | } 61 | 62 | Iterable getJavaSourceDirs() { 63 | return javaSourceDirs; 64 | } 65 | 66 | private void init() throws Exception { 67 | JavaPluginConvention java = project.getConvention().findPlugin(JavaPluginConvention.class); 68 | if (java == null) { 69 | return; 70 | } 71 | 72 | for (SourceSet sourceSet : java.getSourceSets()) { 73 | SourceDirectorySet resourceDirectorySet = sourceSet.getResources(); 74 | Set resourceDirectories = resourceDirectorySet.getSrcDirs(); 75 | for (File resourceDirectory : resourceDirectories) { 76 | File metaInfDir = new File(resourceDirectory, "META-INF"); 77 | if (metaInfDir.exists()) { 78 | File persistenceXmlFileObj = new File(metaInfDir, "persistence.xml"); 79 | if (persistenceXmlFileObj.exists()) { 80 | persistenceXmlFile = persistenceXmlFileObj.getCanonicalPath(); 81 | break; 82 | } 83 | } 84 | } 85 | if (persistenceXmlFile != null) { 86 | SourceDirectorySet allJavaDirectorySet = sourceSet.getAllJava(); 87 | javaSourceDirs = allJavaDirectorySet.getSrcDirs(); 88 | break; 89 | } 90 | } 91 | } 92 | } 93 | } -------------------------------------------------------------------------------- /netbeans-gradle-javaee-models/src/modelBuilders/groovy/org/netbeans/gradle/javaee/models/NbWebModelBuilder.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.javaee.models; 2 | 3 | import java.io.File; 4 | 5 | import org.gradle.api.Project; 6 | import org.gradle.api.plugins.WarPluginConvention; 7 | import org.netbeans.gradle.model.api.ProjectInfoBuilder2; 8 | 9 | /** 10 | * 11 | * @author Ed 12 | */ 13 | enum NbWebModelBuilder implements ProjectInfoBuilder2 { 14 | INSTANCE; 15 | 16 | @Override 17 | public NbWebModel getProjectInfo(Object project) { 18 | return getProjectInfo((Project) project); 19 | } 20 | 21 | private NbWebModel getProjectInfo(Project project) { 22 | WarPluginConvention war = project.getConvention().findPlugin(WarPluginConvention.class); 23 | return war != null ? createModel(project, war) : null; 24 | } 25 | 26 | private NbWebModel createModel(Project project, WarPluginConvention war) { 27 | String webAppDirValue = war.getWebAppDirName(); 28 | String ddValue = "web.xml"; 29 | File deploymentDesc = (File) project.getProperties().get("webXml"); 30 | if (deploymentDesc != null) { 31 | ddValue = deploymentDesc.getName(); 32 | } 33 | return new NbWebModel(webAppDirValue, ddValue); 34 | } 35 | 36 | @Override 37 | public String getName() { 38 | return getClass().getName(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | import java.nio.file.* 2 | 3 | apply plugin: 'java' 4 | apply plugin: 'cz.kubacki.nbm' 5 | apply plugin: 'nbm-dependency-verifier' 6 | 7 | String netbeansVersion = 'RELEASE81' 8 | 9 | repositories { 10 | mavenCentral() 11 | maven { url 'http://bits.netbeans.org/nexus/content/groups/netbeans' } 12 | maven { url 'http://bits.netbeans.org/maven2/' } 13 | maven { url 'http://repo.gradle.org/gradle/libs-releases-local' } 14 | maven { url 'http://dl.bintray.com/kelemen/maven' } 15 | } 16 | 17 | def tryGetProperty = { String name, String defaultValue -> 18 | if (!project.hasProperty(name)) { 19 | return defaultValue 20 | } 21 | 22 | return project.property(name)?.toString() 23 | } 24 | 25 | nbm { 26 | moduleAuthor = 'Ed Hillmann' 27 | licenseFile = 'license.txt' 28 | moduleName = 'org.netbeans.gradle.javaee.project' 29 | localizingBundle = 'org/netbeans/gradle/javaee/plugin/Bundle.properties' 30 | 31 | requires 'cnb.org.netbeans.gradle.project' 32 | 33 | keyStore { 34 | keyStoreFile = tryGetProperty('nbGradlePluginKeyStore', null) 35 | username = tryGetProperty('nbGradlePluginKeyStoreUser', '') 36 | password = tryGetProperty('nbGradlePluginKeyStorePass', '') 37 | } 38 | 39 | friendPackages { 40 | add 'org.netbeans.gradle.javaee.jpa' 41 | add 'org.netbeans.gradle.javaee.web' 42 | } 43 | } 44 | 45 | sourceCompatibility = 1.7 46 | targetCompatibility = 1.7 47 | 48 | configurations { 49 | pluginInstall 50 | } 51 | 52 | def netbeansModule = { String groupName, String moduleName -> 53 | return [ 54 | group: groupName, 55 | name: moduleName, 56 | version: netbeansVersion 57 | ] 58 | } 59 | 60 | dependencies { 61 | compile project(':netbeans-gradle-javaee-models') 62 | 63 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-projectapi') 64 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-api-annotations-common') 65 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-java-project') 66 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-api-java-classpath') 67 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-api-web-webmodule') 68 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-j2ee-core') 69 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-j2ee-dd') 70 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-j2ee-metadata') 71 | providedCompile netbeansModule('org.netbeans.api', 'org-openide-modules') 72 | providedCompile netbeansModule('org.netbeans.api', 'org-openide-util') 73 | providedCompile netbeansModule('org.netbeans.api', 'org-openide-util-lookup') 74 | providedCompile netbeansModule('org.netbeans.api', 'org-openide-filesystems') 75 | providedCompile netbeansModule('org.netbeans.api', 'org-openide-loaders') 76 | providedCompile netbeansModule('org.netbeans.api', 'org-openide-nodes') 77 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-nbjunit') 78 | providedCompile netbeansModule('org.netbeans.api', 'org-netbeans-modules-j2eeserver') 79 | providedCompile netbeansModule('org.netbeans.modules', 'org-netbeans-modules-web-beans') 80 | providedCompile netbeansModule('org.netbeans.modules', 'org-netbeans-modules-j2ee-persistenceapi') 81 | providedCompile netbeansModule('org.netbeans.modules', 'org-netbeans-modules-projectapi-nb') 82 | 83 | providedCompile "com.github.kelemen:netbeans-gradle-plugin:${nbGradleVersion}" 84 | 85 | testCompile 'junit:junit:4.12' 86 | testCompile 'org.mockito:mockito-core:1.9.5' 87 | 88 | // dev-feature: For installation of plugins required by this plugin 89 | // groovy-plugin is not listed here; assumed that full NB version with groovy-support is installed by dev 90 | pluginInstall "com.github.kelemen:netbeans-gradle-plugin:${nbGradleVersion}@nbm" 91 | } 92 | 93 | task extractPlugins << { 94 | def nbms = project.configurations.pluginInstall.findAll {it.name.endsWith(".nbm") } 95 | println nbms 96 | nbms.each { nbm -> 97 | def sourceFile = file(nbm) 98 | def outputDir = file("${buildDir}/tmp/plugins") 99 | copy { 100 | from zipTree(sourceFile) 101 | into outputDir 102 | } 103 | } 104 | } 105 | 106 | task installPlugins(type: Copy, dependsOn: extractPlugins) { 107 | from "${buildDir}/tmp/plugins/netbeans" 108 | into "${buildDir}/module" 109 | } 110 | 111 | run.dependsOn installPlugins 112 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/license.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/jpa/JpaModuleExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.jpa; 7 | 8 | import java.util.concurrent.atomic.AtomicReference; 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import org.netbeans.api.project.Project; 13 | import org.netbeans.gradle.javaee.models.NbJpaModel; 14 | import org.netbeans.gradle.javaee.jpa.verification.GradlePersistenceScopesProvider; 15 | import org.netbeans.gradle.project.api.entry.GradleProjectExtension2; 16 | import org.openide.util.Lookup; 17 | import org.openide.util.lookup.Lookups; 18 | 19 | /** 20 | * 21 | * @author ed 22 | */ 23 | public class JpaModuleExtension implements GradleProjectExtension2 { 24 | 25 | private static final Logger LOGGER = Logger.getLogger(JpaModuleExtension.class.getName()); 26 | 27 | private final Project project; // NetBeans project 28 | private Lookup permanentProjectLookup; 29 | private Lookup projectLookup; 30 | private final Lookup extensionLookup = Lookups.fixed(); 31 | 32 | private final AtomicReference currentModelRef; 33 | 34 | public JpaModuleExtension(Project project) { 35 | this.project = project; 36 | this.currentModelRef = new AtomicReference<>(null); 37 | } 38 | 39 | /** 40 | * Returns the NetBeans Project for the extension 41 | * 42 | * @return a Project object 43 | */ 44 | public Project getProject() { 45 | return project; 46 | } 47 | 48 | public NbJpaModel getCurrentModel() { 49 | return currentModelRef.get(); 50 | } 51 | 52 | @Override 53 | public Lookup getPermanentProjectLookup() { 54 | if (permanentProjectLookup == null) { 55 | permanentProjectLookup = Lookups.fixed(this); 56 | } 57 | return permanentProjectLookup; 58 | } 59 | 60 | @Override 61 | public Lookup getProjectLookup() { 62 | if (projectLookup == null) { 63 | projectLookup = Lookups.fixed( 64 | new GradlePersistenceScopesProvider(this) 65 | ); 66 | } 67 | return projectLookup; 68 | } 69 | 70 | @Override 71 | public Lookup getExtensionLookup() { 72 | return extensionLookup; 73 | } 74 | 75 | @Override 76 | public void activateExtension(NbJpaModel parsedModel) { 77 | if (parsedModel != null) { 78 | LOGGER.log(Level.INFO, "activating Jpa Extension with {0}", parsedModel.getPersistenceFile()); 79 | } 80 | currentModelRef.getAndSet(parsedModel); 81 | } 82 | 83 | @Override 84 | public void deactivateExtension() { 85 | activateExtension(null); 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/jpa/JpaModuleExtensionDef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.jpa; 7 | 8 | import java.io.IOException; 9 | import java.util.Collections; 10 | import java.util.Set; 11 | import java.util.logging.Logger; 12 | 13 | import org.netbeans.api.project.Project; 14 | import org.netbeans.gradle.javaee.models.GradleEEModelBuilders; 15 | import org.netbeans.gradle.javaee.models.NbJpaModel; 16 | import org.netbeans.gradle.project.api.entry.GradleProjectExtension2; 17 | import org.netbeans.gradle.project.api.entry.GradleProjectExtensionDef; 18 | import org.netbeans.gradle.project.api.entry.ModelLoadResult; 19 | import org.netbeans.gradle.project.api.entry.ParsedModel; 20 | import org.netbeans.gradle.project.api.modelquery.GradleModelDef; 21 | import org.netbeans.gradle.project.api.modelquery.GradleModelDefQuery2; 22 | import org.netbeans.gradle.project.api.modelquery.GradleTarget; 23 | import org.openide.modules.SpecificationVersion; 24 | import org.openide.util.Lookup; 25 | import org.openide.util.lookup.Lookups; 26 | import org.openide.util.lookup.ServiceProvider; 27 | 28 | /** 29 | * 30 | * @author ed 31 | */ 32 | @ServiceProvider(service = GradleProjectExtensionDef.class) 33 | public class JpaModuleExtensionDef implements GradleProjectExtensionDef { 34 | 35 | private static final Logger LOGGER = Logger.getLogger(JpaModuleExtensionDef.class.getName()); 36 | private static final String EXTENSION_NAME = "og.netbeans.gradle.javaee.jpa.JpaModuleExtensionDef"; 37 | 38 | private final Lookup extensionLookup; 39 | 40 | public JpaModuleExtensionDef() { 41 | extensionLookup = Lookups.singleton(new Query2()); 42 | } 43 | 44 | @Override 45 | public String getName() { 46 | return EXTENSION_NAME; 47 | } 48 | 49 | @Override 50 | public String getDisplayName() { 51 | return "JavaEE JPA"; 52 | } 53 | 54 | @Override 55 | public Lookup getLookup() { 56 | return extensionLookup; 57 | } 58 | 59 | @Override 60 | public Class getModelType() { 61 | return NbJpaModel.class; 62 | } 63 | 64 | @Override 65 | public ParsedModel parseModel(ModelLoadResult retrievedModels) { 66 | LOGGER.entering(this.getClass().getName(), "parseModel", retrievedModels); 67 | ParsedModel returnValue = null; 68 | NbJpaModel jpaModel = retrievedModels.getMainProjectModels().lookup(NbJpaModel.class); 69 | if (jpaModel != null) { 70 | returnValue = new ParsedModel<>(jpaModel); 71 | } 72 | LOGGER.exiting(this.getClass().getName(), "parseModel", returnValue); 73 | return returnValue; 74 | } 75 | 76 | @Override 77 | public GradleProjectExtension2 createExtension(Project project) throws IOException { 78 | LOGGER.entering(this.getClass().getName(), "createExtension", project); 79 | GradleProjectExtension2 returnValue = new JpaModuleExtension(project); 80 | LOGGER.exiting(this.getClass().getName(), "createExtension", returnValue); 81 | return returnValue; 82 | } 83 | 84 | @Override 85 | public Set getSuppressedExtensions() { 86 | return Collections.emptySet(); 87 | } 88 | 89 | private static final class Query2 implements GradleModelDefQuery2 { 90 | 91 | private static final SpecificationVersion MINIMUM_JDK_VERSION = new SpecificationVersion("1.7"); 92 | private static final GradleModelDef RESULT = GradleModelDef.fromProjectInfoBuilders2(GradleEEModelBuilders.JPA_BUILDER); 93 | 94 | @Override 95 | public GradleModelDef getModelDef(GradleTarget gradleTarget) { 96 | if (gradleTarget.getJavaVersion().compareTo(MINIMUM_JDK_VERSION) < 0) { 97 | return GradleModelDef.EMPTY; 98 | } 99 | return RESULT; 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/jpa/verification/GradlePersistenceScopeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.jpa.verification; 7 | 8 | import org.netbeans.api.java.classpath.ClassPath; 9 | import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; 10 | import org.netbeans.modules.j2ee.persistence.api.metadata.orm.EntityMappingsMetadata; 11 | import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopeImplementation; 12 | import org.openide.filesystems.FileObject; 13 | 14 | /** 15 | * 16 | * @author ed 17 | */ 18 | public class GradlePersistenceScopeImpl implements PersistenceScopeImplementation { 19 | 20 | private FileObject persistenceXml; 21 | private ClassPath classpath; 22 | 23 | public void setPersistenceXml(FileObject persistenceXml) { 24 | this.persistenceXml = persistenceXml; 25 | } 26 | 27 | public void setClassPath(ClassPath classpath) { 28 | this.classpath = classpath; 29 | } 30 | 31 | @Override 32 | public FileObject getPersistenceXml() { 33 | return persistenceXml; 34 | } 35 | 36 | @Override 37 | public ClassPath getClassPath() { 38 | return classpath; 39 | } 40 | 41 | @Override 42 | public MetadataModel getEntityMappingsModel(String string) { 43 | return null; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/jpa/verification/GradlePersistenceScopesImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.jpa.verification; 7 | 8 | import java.beans.PropertyChangeListener; 9 | import java.io.File; 10 | import java.net.URL; 11 | import java.util.List; 12 | 13 | import org.netbeans.api.java.classpath.ClassPath; 14 | import org.netbeans.gradle.javaee.jpa.JpaModuleExtension; 15 | import org.netbeans.modules.j2ee.persistence.api.PersistenceScope; 16 | import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopeFactory; 17 | import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesImplementation; 18 | import org.netbeans.spi.java.classpath.support.ClassPathSupport; 19 | import org.openide.filesystems.FileUtil; 20 | 21 | /** 22 | * 23 | * @author ed 24 | */ 25 | public class GradlePersistenceScopesImpl implements PersistenceScopesImplementation { 26 | 27 | private static final PersistenceScope[] EMPTY = new PersistenceScope[0]; 28 | 29 | private final JpaModuleExtension jpaModule; 30 | 31 | public GradlePersistenceScopesImpl(JpaModuleExtension jpaModule) { 32 | this.jpaModule = jpaModule; 33 | } 34 | 35 | private PersistenceScope[] constructScopes(JpaModuleExtension jpaModule) { 36 | if (jpaModule.getCurrentModel() == null) { 37 | return EMPTY; 38 | } 39 | 40 | PersistenceScope[] returnValue = new PersistenceScope[1]; 41 | GradlePersistenceScopeImpl scope = new GradlePersistenceScopeImpl(); 42 | scope.setPersistenceXml( 43 | FileUtil.toFileObject( 44 | new File(jpaModule.getCurrentModel().getPersistenceFile()))); 45 | scope.setClassPath(buildClasspath(jpaModule.getCurrentModel().getJavaSourceDirs())); 46 | returnValue[0] = PersistenceScopeFactory.createPersistenceScope(scope); 47 | return returnValue; 48 | } 49 | 50 | private ClassPath buildClasspath(Iterable classpath) { 51 | List pathList = new java.util.ArrayList<>(); 52 | for (File classpathFile: classpath) { 53 | pathList.add(FileUtil.urlForArchiveOrDir(classpathFile)); 54 | } 55 | URL[] files = pathList.toArray(new URL[pathList.size()]); 56 | return ClassPathSupport.createClassPath(files); 57 | } 58 | 59 | @Override 60 | public PersistenceScope[] getPersistenceScopes() { 61 | return constructScopes(jpaModule); 62 | } 63 | 64 | @Override 65 | public void addPropertyChangeListener(PropertyChangeListener pl) { 66 | } 67 | 68 | @Override 69 | public void removePropertyChangeListener(PropertyChangeListener pl) { 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/jpa/verification/GradlePersistenceScopesProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.jpa.verification; 7 | 8 | import org.netbeans.gradle.javaee.jpa.JpaModuleExtension; 9 | import org.netbeans.modules.j2ee.persistence.api.PersistenceScopes; 10 | import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesFactory; 11 | import org.netbeans.modules.j2ee.persistence.spi.PersistenceScopesProvider; 12 | 13 | /** 14 | * 15 | * @author ed 16 | */ 17 | public class GradlePersistenceScopesProvider implements PersistenceScopesProvider { 18 | 19 | private final GradlePersistenceScopesImpl persistenceScopesImpl; 20 | 21 | public GradlePersistenceScopesProvider(JpaModuleExtension jpaModule) { 22 | this.persistenceScopesImpl = new GradlePersistenceScopesImpl(jpaModule); 23 | } 24 | 25 | @Override 26 | public PersistenceScopes getPersistenceScopes() { 27 | return PersistenceScopesFactory.createPersistenceScopes(persistenceScopesImpl); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/GradleWebModuleImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package org.netbeans.gradle.javaee.web; 8 | 9 | import java.beans.PropertyChangeListener; 10 | import java.util.logging.Level; 11 | import java.util.logging.Logger; 12 | 13 | import org.netbeans.api.j2ee.core.Profile; 14 | import org.netbeans.api.java.classpath.ClassPath; 15 | import org.netbeans.api.java.project.JavaProjectConstants; 16 | import org.netbeans.api.project.Project; 17 | import org.netbeans.api.project.ProjectUtils; 18 | import org.netbeans.api.project.SourceGroup; 19 | import org.netbeans.api.project.Sources; 20 | import org.netbeans.gradle.javaee.models.NbWebModel; 21 | import org.netbeans.modules.j2ee.dd.api.web.WebAppMetadata; 22 | import org.netbeans.modules.j2ee.dd.spi.MetadataUnit; 23 | import org.netbeans.modules.j2ee.dd.spi.web.WebAppMetadataModelFactory; 24 | import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel; 25 | import org.netbeans.modules.web.spi.webmodule.WebModuleImplementation2; 26 | import org.openide.filesystems.FileObject; 27 | import org.openide.filesystems.FileUtil; 28 | 29 | /** 30 | * 31 | * @author Ed 32 | */ 33 | public class GradleWebModuleImpl implements WebModuleImplementation2 { 34 | 35 | private static final Logger LOGGER = Logger.getLogger(GradleWebModuleImpl.class.getName()); 36 | 37 | private final WebModuleExtension webExt; 38 | private FileObject documentBase; 39 | private FileObject webInf; 40 | private FileObject deploymentDescriptor; 41 | 42 | public GradleWebModuleImpl(WebModuleExtension webExt) { 43 | this.webExt = webExt; 44 | initialise(); 45 | } 46 | 47 | private void initialise() { 48 | if (webExt == null) { 49 | return; 50 | } 51 | 52 | NbWebModel model = webExt.getCurrentModel(); 53 | LOGGER.log(Level.FINER, "model = {0}", model); 54 | 55 | if (model == null) { 56 | return; 57 | } 58 | 59 | LOGGER.log(Level.FINER, "model.getWebAppDir() = {0}", model.getWebAppDir()); 60 | documentBase = webExt.getProject().getProjectDirectory().getFileObject(model.getWebAppDir()); 61 | if (documentBase != null) { 62 | webInf = documentBase.getFileObject("WEB-INF"); 63 | LOGGER.log(Level.FINER, "webInf = {0}", webInf); 64 | LOGGER.log(Level.FINER, "model.getDeploymentDescName() = {0}", model.getDeploymentDescName()); 65 | if (webInf != null) { 66 | deploymentDescriptor = webInf.getFileObject(model.getDeploymentDescName()); 67 | } 68 | } 69 | } 70 | 71 | private FileObject[] getSourcesForNBProject(Project project) { 72 | Sources sources = ProjectUtils.getSources(project); 73 | if (sources == null) { 74 | return new FileObject[0]; 75 | } 76 | SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 77 | FileObject[] returnValue = new FileObject[groups.length]; 78 | int idx = 0; 79 | for (SourceGroup group : groups) { 80 | returnValue[idx++] = group.getRootFolder(); 81 | } 82 | return returnValue; 83 | } 84 | 85 | @Override 86 | public FileObject getDocumentBase() { 87 | return documentBase; 88 | } 89 | 90 | @Override 91 | public String getContextPath() { 92 | /* 93 | TODO Returns the context path of the web module. 94 | // read from glassfish-web.xml? 95 | */ 96 | return "/"; 97 | } 98 | 99 | @Override 100 | public Profile getJ2eeProfile() { 101 | return Profile.JAVA_EE_6_WEB; 102 | } 103 | 104 | @Override 105 | public FileObject getWebInf() { 106 | return webInf; 107 | } 108 | 109 | @Override 110 | public FileObject getDeploymentDescriptor() { 111 | return deploymentDescriptor; 112 | } 113 | 114 | @Override 115 | @Deprecated 116 | public FileObject[] getJavaSources() { 117 | return getSourcesForNBProject(webExt.getProject()); 118 | } 119 | 120 | @Override 121 | public MetadataModel getMetadataModel() { 122 | // TODO get classpaths from Gradle? 123 | MetadataUnit metadataUnit = MetadataUnit.create(ClassPath.EMPTY, ClassPath.EMPTY, ClassPath.EMPTY, 124 | FileUtil.toFile(deploymentDescriptor)); 125 | return WebAppMetadataModelFactory.createMetadataModel(metadataUnit, true); 126 | } 127 | 128 | @Override 129 | public void addPropertyChangeListener(PropertyChangeListener pl) { 130 | } 131 | 132 | @Override 133 | public void removePropertyChangeListener(PropertyChangeListener pl) { 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/GradleWebModuleProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package org.netbeans.gradle.javaee.web; 8 | 9 | import java.util.logging.Logger; 10 | 11 | import org.netbeans.api.project.FileOwnerQuery; 12 | import org.netbeans.api.project.Project; 13 | import org.netbeans.modules.web.api.webmodule.WebModule; 14 | import org.netbeans.modules.web.spi.webmodule.WebModuleFactory; 15 | import org.netbeans.modules.web.spi.webmodule.WebModuleProvider; 16 | import org.openide.filesystems.FileObject; 17 | 18 | /** 19 | * 20 | * @author Ed 21 | */ 22 | public class GradleWebModuleProvider implements WebModuleProvider { 23 | 24 | private static final Logger LOGGER = Logger.getLogger(GradleWebModuleProvider.class.getName()); 25 | 26 | private final WebModuleExtension webExt; 27 | private volatile WebModule webModule; 28 | 29 | public GradleWebModuleProvider(WebModuleExtension webExt) { 30 | this.webExt = webExt; 31 | } 32 | 33 | @Override 34 | public WebModule findWebModule(FileObject fo) { 35 | LOGGER.entering(GradleWebModuleProvider.class.getName(), "findWebModule"); 36 | WebModule returnValue = null; 37 | if (webExt != null) { 38 | Project fileOwner = FileOwnerQuery.getOwner(fo); 39 | if (webExt.getProject().equals(fileOwner)) { 40 | returnValue = getWebModule(); 41 | } 42 | } 43 | LOGGER.exiting(GradleWebModuleProvider.class.getName(), "findWebModule", returnValue); 44 | return returnValue; 45 | } 46 | 47 | private WebModule getWebModule() { 48 | if (webModule == null) { 49 | initWebModule(); 50 | } 51 | return webModule; 52 | } 53 | 54 | private synchronized void initWebModule() { 55 | if (webModule == null) { 56 | webModule = WebModuleFactory.createWebModule(new GradleWebModuleImpl(webExt)); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/ModelReloadListener.java: -------------------------------------------------------------------------------- 1 | package org.netbeans.gradle.javaee.web; 2 | 3 | import org.netbeans.gradle.javaee.models.NbWebModel; 4 | 5 | public interface ModelReloadListener { 6 | public void onModelChange(NbWebModel prevModel, NbWebModel newModel); 7 | } 8 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/WebModuleExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package org.netbeans.gradle.javaee.web; 8 | 9 | import java.util.concurrent.atomic.AtomicReference; 10 | 11 | import org.netbeans.api.project.Project; 12 | import org.netbeans.gradle.javaee.models.NbWebModel; 13 | import org.netbeans.gradle.javaee.web.nodes.WebModuleExtensionNodes; 14 | import org.netbeans.gradle.javaee.web.sources.GradleWebProjectSources; 15 | import org.netbeans.gradle.project.api.entry.GradleProjectExtension2; 16 | import org.netbeans.modules.web.beans.WebCdiUtil; 17 | import org.openide.filesystems.FileObject; 18 | import org.openide.util.Lookup; 19 | import org.openide.util.lookup.Lookups; 20 | 21 | /** 22 | * 23 | * @author Ed 24 | */ 25 | public class WebModuleExtension implements GradleProjectExtension2 { 26 | 27 | private final Project project; // NetBeans project 28 | private Lookup permanentProjectLookup; 29 | private Lookup projectLookup; 30 | private Lookup extensionLookup; 31 | 32 | private final AtomicReference currentModelRef; 33 | 34 | public WebModuleExtension(Project project) { 35 | this.project = project; 36 | this.currentModelRef = new AtomicReference<>(null); 37 | } 38 | 39 | @Override 40 | public synchronized Lookup getPermanentProjectLookup() { 41 | if (permanentProjectLookup == null) { 42 | permanentProjectLookup = Lookups.fixed(this); 43 | } 44 | return permanentProjectLookup; 45 | } 46 | 47 | @Override 48 | public synchronized Lookup getProjectLookup() { 49 | if (projectLookup == null) { 50 | projectLookup = Lookups.fixed( 51 | new GradleWebModuleProvider(this), 52 | new WebCdiUtil(project), 53 | new GradleWebProjectSources(this) 54 | ); 55 | } 56 | return projectLookup; 57 | } 58 | 59 | @Override 60 | public synchronized Lookup getExtensionLookup() { 61 | if (extensionLookup == null) { 62 | extensionLookup = Lookups.fixed( 63 | new WebModuleExtensionNodes(this) 64 | ); 65 | } 66 | return extensionLookup; 67 | } 68 | 69 | @Override 70 | public void activateExtension(NbWebModel parsedModel) { 71 | NbWebModel prevModel = currentModelRef.getAndSet(parsedModel); 72 | for (ModelReloadListener listener: getExtensionLookup().lookupAll(ModelReloadListener.class)) { 73 | listener.onModelChange(prevModel, parsedModel); 74 | } 75 | } 76 | 77 | @Override 78 | public void deactivateExtension() { 79 | activateExtension(null); 80 | } 81 | 82 | public NbWebModel getCurrentModel() { 83 | return currentModelRef.get(); 84 | } 85 | 86 | public Project getProject() { 87 | return project; 88 | } 89 | 90 | public FileObject getWebDir() { 91 | NbWebModel model = getCurrentModel(); 92 | return model != null 93 | ? project.getProjectDirectory().getFileObject(model.getWebAppDir()) 94 | : null; 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/WebModuleExtensionDef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package org.netbeans.gradle.javaee.web; 8 | 9 | import java.io.IOException; 10 | import java.util.Collections; 11 | import java.util.Set; 12 | import java.util.logging.Logger; 13 | 14 | import org.netbeans.api.project.Project; 15 | import org.netbeans.gradle.javaee.models.GradleEEModelBuilders; 16 | import org.netbeans.gradle.javaee.models.NbWebModel; 17 | import org.netbeans.gradle.project.api.entry.GradleProjectExtension2; 18 | import org.netbeans.gradle.project.api.entry.GradleProjectExtensionDef; 19 | import org.netbeans.gradle.project.api.entry.ModelLoadResult; 20 | import org.netbeans.gradle.project.api.entry.ParsedModel; 21 | import org.netbeans.gradle.project.api.modelquery.GradleModelDef; 22 | import org.netbeans.gradle.project.api.modelquery.GradleModelDefQuery2; 23 | import org.netbeans.gradle.project.api.modelquery.GradleTarget; 24 | import org.openide.modules.SpecificationVersion; 25 | import org.openide.util.Lookup; 26 | import org.openide.util.lookup.Lookups; 27 | import org.openide.util.lookup.ServiceProvider; 28 | 29 | /** 30 | * 31 | * @author Ed 32 | */ 33 | @ServiceProvider(service = GradleProjectExtensionDef.class) 34 | public class WebModuleExtensionDef implements GradleProjectExtensionDef { 35 | 36 | private static final Logger LOGGER = Logger.getLogger(WebModuleExtensionDef.class.getName()); 37 | 38 | private static final String EXTENSION_NAME = "org.netbeans.gradle.javaee.web.WebModuleExtensionDef"; 39 | 40 | private final Lookup extensionLookup; 41 | 42 | public WebModuleExtensionDef() { 43 | extensionLookup = Lookups.singleton(new Query2()); 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return EXTENSION_NAME; 49 | } 50 | 51 | @Override 52 | public String getDisplayName() { 53 | return "JavaEE Web"; 54 | } 55 | 56 | @Override 57 | public Lookup getLookup() { 58 | return extensionLookup; 59 | } 60 | 61 | @Override 62 | public Class getModelType() { 63 | return NbWebModel.class; 64 | } 65 | 66 | @Override 67 | public ParsedModel parseModel(ModelLoadResult retrievedModels) { 68 | LOGGER.entering(this.getClass().getName(), "parseModel", retrievedModels); 69 | ParsedModel returnValue = null; 70 | NbWebModel webModel = retrievedModels.getMainProjectModels().lookup(NbWebModel.class); 71 | if (webModel != null) { 72 | returnValue = new ParsedModel<>(webModel); 73 | } 74 | LOGGER.exiting(this.getClass().getName(), "parseModel", returnValue); 75 | return returnValue; 76 | } 77 | 78 | @Override 79 | public GradleProjectExtension2 createExtension(Project project) throws IOException { 80 | LOGGER.entering(this.getClass().getName(), "createExtension", project); 81 | GradleProjectExtension2 returnValue = new WebModuleExtension(project); 82 | LOGGER.exiting(this.getClass().getName(), "createExtension", returnValue); 83 | return returnValue; 84 | } 85 | 86 | @Override 87 | public Set getSuppressedExtensions() { 88 | return Collections.emptySet(); 89 | } 90 | 91 | private static final class Query2 implements GradleModelDefQuery2 { 92 | 93 | private static final SpecificationVersion MINIMUM_JDK_VERSION = new SpecificationVersion("1.7"); 94 | private static final GradleModelDef RESULT = GradleModelDef.fromProjectInfoBuilders2(GradleEEModelBuilders.WEB_BUILDER); 95 | 96 | @Override 97 | public GradleModelDef getModelDef(GradleTarget gradleTarget) { 98 | if (gradleTarget.getJavaVersion().compareTo(MINIMUM_JDK_VERSION) < 0) { 99 | return GradleModelDef.EMPTY; 100 | } 101 | return RESULT; 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/nodes/WebModuleExtensionNodes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | 7 | package org.netbeans.gradle.javaee.web.nodes; 8 | 9 | import org.netbeans.gradle.javaee.web.WebModuleExtension; 10 | import org.netbeans.gradle.project.api.event.NbListenerRef; 11 | import org.netbeans.gradle.project.api.nodes.GradleProjectExtensionNodes; 12 | import org.netbeans.gradle.project.api.nodes.ManualRefreshedNodes; 13 | import org.netbeans.gradle.project.api.nodes.SingleNodeFactory; 14 | import org.openide.filesystems.FileObject; 15 | import org.openide.loaders.DataFolder; 16 | import org.openide.nodes.FilterNode; 17 | import org.openide.nodes.Node; 18 | 19 | import java.util.List; 20 | import java.util.Objects; 21 | import java.util.logging.Level; 22 | import java.util.logging.Logger; 23 | 24 | import javax.swing.event.ChangeEvent; 25 | import javax.swing.event.ChangeListener; 26 | import org.netbeans.gradle.javaee.web.ModelReloadListener; 27 | import org.netbeans.gradle.javaee.models.NbWebModel; 28 | import org.netbeans.gradle.project.api.event.NbListenerRefs; 29 | import org.openide.util.ChangeSupport; 30 | 31 | /** 32 | * 33 | * @author Ed 34 | */ 35 | @ManualRefreshedNodes 36 | public class WebModuleExtensionNodes implements GradleProjectExtensionNodes, ModelReloadListener { 37 | 38 | private static final Logger LOGGER = Logger.getLogger(WebModuleExtensionNodes.class.getName()); 39 | 40 | private final WebModuleExtension webModule; 41 | private final ChangeSupport nodeChanges; 42 | 43 | public WebModuleExtensionNodes(WebModuleExtension webModule) { 44 | this.webModule = webModule; 45 | this.nodeChanges = new ChangeSupport(this); 46 | } 47 | 48 | private static boolean hasChanged(NbWebModel prevModel, NbWebModel newModel) { 49 | if (prevModel == newModel) { 50 | return false; 51 | } 52 | 53 | if (prevModel == null || newModel == null) { 54 | return true; 55 | } 56 | 57 | return !Objects.equals(prevModel.getWebAppDir(), newModel.getWebAppDir()); 58 | } 59 | 60 | @Override 61 | public void onModelChange(NbWebModel prevModel, NbWebModel newModel) { 62 | if (hasChanged(prevModel, newModel)) { 63 | nodeChanges.fireChange(); 64 | } 65 | } 66 | 67 | @Override 68 | public NbListenerRef addNodeChangeListener(final Runnable listener) { 69 | final ChangeListener changeListener = new ChangeListener() { 70 | @Override 71 | public void stateChanged(ChangeEvent e) { 72 | listener.run(); 73 | } 74 | }; 75 | 76 | nodeChanges.addChangeListener(changeListener); 77 | return NbListenerRefs.fromRunnable(new Runnable() { 78 | @Override 79 | public void run() { 80 | nodeChanges.removeChangeListener(changeListener); 81 | } 82 | }); 83 | } 84 | 85 | @Override 86 | public List getNodeFactories() { 87 | List returnValue = new java.util.LinkedList<>(); 88 | addWebDir(returnValue); 89 | return returnValue; 90 | } 91 | 92 | private void addWebDir(List list) { 93 | FileObject webDir = webModule.getWebDir(); 94 | LOGGER.log(Level.FINEST, "webDir = {0}", webDir); 95 | if (webDir != null) { 96 | final DataFolder listedFolder = DataFolder.findFolder(webDir); 97 | LOGGER.log(Level.FINEST, "listedFolder = {0}", listedFolder); 98 | list.add(new SingleNodeFactory() { 99 | @Override 100 | public Node createNode() { 101 | return new FilterNode(listedFolder.getNodeDelegate().cloneNode()) { 102 | @Override 103 | public String getDisplayName() { 104 | return "Web Pages"; 105 | } 106 | }; 107 | } 108 | }); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/java/org/netbeans/gradle/javaee/web/sources/GradleWebProjectSources.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this license header, choose License Headers in Project Properties. 3 | * To change this template file, choose Tools | Templates 4 | * and open the template in the editor. 5 | */ 6 | package org.netbeans.gradle.javaee.web.sources; 7 | 8 | import java.beans.PropertyChangeListener; 9 | import java.beans.PropertyChangeSupport; 10 | import java.net.URI; 11 | 12 | import javax.swing.Icon; 13 | import javax.swing.event.ChangeListener; 14 | 15 | import org.netbeans.api.project.SourceGroup; 16 | import org.netbeans.api.project.Sources; 17 | import org.netbeans.gradle.javaee.web.WebModuleExtension; 18 | import org.openide.filesystems.FileObject; 19 | import org.openide.filesystems.FileUtil; 20 | 21 | /** 22 | * 23 | * @author ed 24 | */ 25 | public class GradleWebProjectSources implements Sources { 26 | 27 | private static final String DOC_ROOT = "doc_root"; 28 | 29 | private final WebModuleExtension webExt; 30 | 31 | public GradleWebProjectSources(WebModuleExtension webExt) { 32 | this.webExt = webExt; 33 | } 34 | 35 | @Override 36 | public SourceGroup[] getSourceGroups(String sourceGroupType) { 37 | if (DOC_ROOT.equals(sourceGroupType)) { 38 | return new SourceGroup[]{new GradleSourceGroup(webExt.getWebDir(), "Web Resources [doc_root]")}; 39 | } else { 40 | return new SourceGroup[0]; 41 | } 42 | } 43 | 44 | @Override 45 | public void addChangeListener(ChangeListener cl) { 46 | // TODO 47 | } 48 | 49 | @Override 50 | public void removeChangeListener(ChangeListener cl) { 51 | // TODO 52 | } 53 | 54 | private static class GradleSourceGroup implements SourceGroup { 55 | 56 | private final FileObject location; 57 | private final PropertyChangeSupport changes; 58 | private final String displayName; 59 | 60 | public GradleSourceGroup(FileObject location, String displayName) { 61 | this.location = location; 62 | this.displayName = displayName; 63 | this.changes = new PropertyChangeSupport(this); 64 | } 65 | 66 | @Override 67 | public FileObject getRootFolder() { 68 | return location; 69 | } 70 | 71 | @Override 72 | public String getName() { 73 | String locationStr = location.getPath(); 74 | return locationStr.length() > 0 ? locationStr : "generic"; 75 | } 76 | 77 | @Override 78 | public String getDisplayName() { 79 | return displayName; 80 | } 81 | 82 | @Override 83 | public Icon getIcon(boolean opened) { 84 | return null; 85 | } 86 | 87 | @Override 88 | public boolean contains(FileObject file) { 89 | if (file == location) { 90 | return true; 91 | } 92 | 93 | if (FileUtil.getRelativePath(location, file) == null) { 94 | return false; 95 | } 96 | 97 | URI f = file.toURI(); 98 | 99 | // else MIXED, UNKNOWN, or SHARABLE; or not a disk file 100 | // return f == null || SharabilityQuery.getSharability(f) != SharabilityQuery.Sharability.NOT_SHARABLE; 101 | return f == null; 102 | } 103 | 104 | @Override 105 | public void addPropertyChangeListener(PropertyChangeListener l) { 106 | changes.addPropertyChangeListener(l); 107 | } 108 | 109 | @Override 110 | public void removePropertyChangeListener(PropertyChangeListener l) { 111 | changes.removePropertyChangeListener(l); 112 | } 113 | 114 | @Override 115 | public String toString() { 116 | return "GradleWebProjectSources.Group[name=" + getName() + ",rootFolder=" + getRootFolder() + "]"; 117 | } 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/nbm/manifest.mf: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | OpenIDE-Module-Localizing-Bundle: org/netbeans/gradle/javaee/plugin/Bundle.properties 3 | -------------------------------------------------------------------------------- /netbeans-gradle-javaee-plugin/src/main/resources/org/netbeans/gradle/javaee/plugin/Bundle.properties: -------------------------------------------------------------------------------- 1 | OpenIDE-Module-Display-Category=Gradle 2 | OpenIDE-Module-Name=Gradle JavaEE Support 3 | OpenIDE-Module-Short-Description= 4 | OpenIDE-Module-Long-Description= 5 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'netbeans-gradle-javaee-project'; 2 | 3 | def subDirs = rootDir.listFiles(new FileFilter() { 4 | public boolean accept(File file) { 5 | return file.isDirectory(); 6 | } 7 | }); 8 | 9 | subDirs.each { File dir -> 10 | String dirName = dir.name; 11 | if (dirName.toLowerCase(Locale.US) != "buildsrc" && new File(dir, 'build.gradle').exists()) { 12 | include dirName; 13 | } 14 | } 15 | --------------------------------------------------------------------------------