-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-1100: Introduced ConfigurationFactory and ConfigurationProducer
- Loading branch information
Showing
6 changed files
with
104 additions
and
51 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
15 changes: 15 additions & 0 deletions
15
shell-api/src/main/java/org/jboss/forge/env/ConfigurationFactory.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,15 @@ | ||
package org.jboss.forge.env; | ||
|
||
import org.jboss.forge.project.Project; | ||
|
||
/** | ||
* Creates {@link Configuration} objects for the requested scopes | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public interface ConfigurationFactory | ||
{ | ||
public Configuration getUserConfig(); | ||
|
||
public Configuration getProjectConfig(Project project); | ||
} |
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
49 changes: 49 additions & 0 deletions
49
shell/src/main/java/org/jboss/forge/shell/env/ConfigurationProducer.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,49 @@ | ||
package org.jboss.forge.shell.env; | ||
|
||
import javax.enterprise.event.Event; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
import org.jboss.forge.env.Configuration; | ||
import org.jboss.forge.env.ConfigurationException; | ||
import org.jboss.forge.env.ConfigurationFacet; | ||
import org.jboss.forge.env.ConfigurationFactory; | ||
import org.jboss.forge.project.Project; | ||
import org.jboss.forge.project.facets.events.InstallFacets; | ||
import org.jboss.forge.shell.Shell; | ||
|
||
public class ConfigurationProducer | ||
{ | ||
|
||
@Inject | ||
private ConfigurationFactory factory; | ||
|
||
@Inject | ||
private Event<InstallFacets> installFacets; | ||
|
||
/** | ||
* Returns a project-scoped configuration (if a project is in scope). Falls back to the user scope configuration if | ||
* no project is set in the shell | ||
* | ||
* @return | ||
* @throws ConfigurationException | ||
*/ | ||
@Produces | ||
public Configuration getConfiguration(Shell shell) throws ConfigurationException | ||
{ | ||
Project project = shell.getCurrentProject(); | ||
if (project == null) | ||
{ | ||
return factory.getUserConfig(); | ||
} | ||
if (!project.hasFacet(ConfigurationFacet.class)) | ||
{ | ||
installFacets.fire(new InstallFacets(ConfigurationFacet.class)); | ||
// // Installing manually | ||
// ConfigurationFacet facet = new ConfigurationFacet(factory); | ||
// facet.setProject(project); | ||
// project.installFacet(facet); | ||
} | ||
return project.getFacet(ConfigurationFacet.class).getConfiguration(); | ||
} | ||
} |
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
1 change: 0 additions & 1 deletion
1
shell/src/test/java/org/jboss/forge/env/ConfigurationFacetTest.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