-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration tests are now run in temporary directory. Implemented
GradleManager.
- Loading branch information
1 parent
e6c41f0
commit 5524f7c
Showing
8 changed files
with
212 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
api/src/main/java/org/jboss/forge/addon/gradle/projects/GradleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.addon.gradle.projects; | ||
|
||
import org.jboss.forge.furnace.services.Exported; | ||
|
||
/** | ||
* @author Adam Wyłuda | ||
*/ | ||
@Exported | ||
public interface GradleManager | ||
{ | ||
boolean runGradleBuild(String directory, String task, String profile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
impl/src/main/java/org/jboss/forge/addon/gradle/projects/GradleConnectionManager.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
impl/src/main/java/org/jboss/forge/addon/gradle/projects/GradleManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.addon.gradle.projects; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
import org.gradle.jarjar.com.google.common.base.Preconditions; | ||
import org.gradle.tooling.BuildLauncher; | ||
import org.gradle.tooling.GradleConnectionException; | ||
import org.gradle.tooling.GradleConnector; | ||
import org.gradle.tooling.ProjectConnection; | ||
import org.gradle.tooling.ResultHandler; | ||
import org.jboss.forge.furnace.util.Strings; | ||
|
||
/** | ||
* @author Adam Wyłuda | ||
*/ | ||
public class GradleManagerImpl implements GradleManager | ||
{ | ||
private static class ResultHolder | ||
{ | ||
private volatile boolean result; | ||
} | ||
|
||
@Override | ||
public boolean runGradleBuild(String directory, String task, String profile) | ||
{ | ||
String gradleHome = System.getenv("GRADLE_HOME"); | ||
Preconditions.checkArgument(!Strings.isNullOrEmpty(gradleHome), "GRADLE_HOME not set"); | ||
|
||
GradleConnector connector = GradleConnector.newConnector(); | ||
ProjectConnection connection = connector | ||
.forProjectDirectory(new File(directory)) | ||
.useGradleUserHomeDir(new File(gradleHome)) | ||
.connect(); | ||
|
||
BuildLauncher launcher = connection.newBuild().forTasks(task); | ||
if (!Strings.isNullOrEmpty(profile)) | ||
{ | ||
launcher.withArguments("-Pprofile=" + profile); | ||
} | ||
|
||
final ResultHolder holder = new ResultHolder(); | ||
final CountDownLatch latch = new CountDownLatch(1); | ||
|
||
launcher.run(new ResultHandler<Object>() | ||
{ | ||
@Override | ||
public void onComplete(Object result) | ||
{ | ||
holder.result = true; | ||
latch.countDown(); | ||
} | ||
|
||
@Override | ||
public void onFailure(GradleConnectionException failure) | ||
{ | ||
holder.result = false; | ||
latch.countDown(); | ||
} | ||
}); | ||
|
||
try | ||
{ | ||
latch.await(); | ||
} | ||
catch (InterruptedException e) | ||
{ | ||
e.printStackTrace(); | ||
} | ||
|
||
return holder.result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/src/test/java/org/jboss/forge/addon/gradle/projects/GradleTestProjectProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.addon.gradle.projects; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.forge.addon.projects.Project; | ||
import org.jboss.forge.addon.projects.ProjectFactory; | ||
import org.jboss.forge.addon.resource.DirectoryResource; | ||
import org.jboss.forge.addon.resource.FileResource; | ||
import org.jboss.forge.addon.resource.ResourceFactory; | ||
import org.jboss.forge.furnace.Furnace; | ||
import org.jboss.forge.furnace.services.Exported; | ||
|
||
/** | ||
* @author Adam Wyłuda | ||
*/ | ||
@Exported | ||
public class GradleTestProjectProvider | ||
{ | ||
@Inject | ||
private Furnace furnace; | ||
@Inject | ||
private GradleProjectLocator locator; | ||
@Inject | ||
private ProjectFactory projectFactory; | ||
@Inject | ||
private ResourceFactory resourceFactory; | ||
|
||
private DirectoryResource projectDir; | ||
|
||
public Project create() | ||
{ | ||
DirectoryResource addonDir = resourceFactory.create(furnace.getRepositories().get(0).getRootDirectory()).reify( | ||
DirectoryResource.class); | ||
projectDir = addonDir.createTempResource(); | ||
FileResource<?> gradleFile = projectDir.getChild("build.gradle").reify(FileResource.class); | ||
gradleFile.createNewFile(); | ||
gradleFile.setContents(getClass().getResourceAsStream("/build.gradle")); | ||
return findProject(); | ||
} | ||
|
||
public Project findProject() | ||
{ | ||
return projectFactory.findProject(projectDir); | ||
} | ||
|
||
public void clean() | ||
{ | ||
projectDir.delete(true); | ||
} | ||
} |
Oops, something went wrong.