Skip to content

Commit

Permalink
Merge pull request #115 from gradle/tt/refine-project-specs
Browse files Browse the repository at this point in the history
Refine Init Project Specs
  • Loading branch information
tresat authored Aug 14, 2024
2 parents e5bdc15 + 2067515 commit 26b66a3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion unified-prototype/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-8.11-20240812191308+0000-bin.zip
distributionUrl=https\://services.gradle.org/distributions-snapshots/gradle-8.11-20240814172604+0000-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* as resources files in the {@link #TEMPLATES_ROOT} directory.
*/
@SuppressWarnings("UnstableApiUsage")
public final class StaticProjectGenerator implements InitProjectGenerator {
public abstract class StaticProjectGenerator implements InitProjectGenerator {
private static final String TEMPLATES_ROOT = "templates";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void extractResourcesFromJar(String relativePath, File destDir) throws IO
throw new IllegalArgumentException("Directory: '" + relativePath + "' not found on classpath.");
}
JarFile jarFile = ((JarURLConnection) jarDirURL.openConnection()).getJarFile();
System.out.println("Using URL: " + jarDirURL);

Iterator<JarEntry> iterator = jarFile.entries().asIterator();
while (iterator.hasNext()) {
Expand All @@ -39,21 +38,15 @@ public void extractResourcesFromJar(String relativePath, File destDir) throws IO

if (entryName.startsWith(relativePath)) {
String entrySuffix = entryName.substring(relativePath.length());
System.out.println("Entry: " + entry + " name: " + entryName + " suffix: " + entrySuffix);
File destFile = new File(destDir, entrySuffix);
System.out.println("Dest file: " + destFile);

if (entry.isDirectory()) {
System.out.println("Is directory");
FileUtils.forceMkdir(destFile);
System.out.println("Created directory");
} else {
System.out.println("Is file");
try (InputStream is = jarFile.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(destFile)) {
IOUtils.copy(is, fos);
}
System.out.println("Copied file");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public List<InitProjectSpec> getProjectSpecs() {
}

@Override
public InitProjectGenerator getProjectGenerator() {
return new StaticProjectGenerator();
public Class<? extends InitProjectGenerator> getProjectGenerator() {
return StaticProjectGenerator.class;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package templates.`java-application`

javaApplication {
// compile for 17
javaVersion = 17
mainClass = "com.example.App"

dependencies {
implementation(project(":java-util"))
implementation("com.google.guava:guava:32.1.3-jre")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
google() // for Android plugin
gradlePluginPortal()
}
}

plugins {
id("org.gradle.experimental.jvm-ecosystem") version "0.1.10"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example;

import com.example.utils.Utils;
import com.google.common.collect.ImmutableList;

public class App {
Expand All @@ -9,10 +8,6 @@ public static void main(String[] args) {
ImmutableList.Builder<String> builder = ImmutableList.builder();
builder.add("Hello from Java " + System.getProperty("java.version"));

// Verify that the Java library is available
Utils utils = new Utils();
builder.add(utils.getWelcome());

ImmutableList<String> messages = builder.build();
messages.forEach(System.out::println);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ javaLibrary {
javaVersion = 21

dependencies {
implementation(project(":java-util"))
implementation("com.google.guava:guava:32.1.3-jre")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pluginManagement {
repositories {
google() // for Android plugin
gradlePluginPortal()
}
}

plugins {
id("org.gradle.experimental.jvm-ecosystem") version "0.1.10"
}

0 comments on commit 26b66a3

Please sign in to comment.