-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new project wizard to create a subproject of a multi-project …
…build.
- Loading branch information
Showing
5 changed files
with
251 additions
and
1 deletion.
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
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
101 changes: 101 additions & 0 deletions
101
src/org/netbeans/gradle/project/newproject/GradleSubProjectConfigPanel.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,101 @@ | ||
package org.netbeans.gradle.project.newproject; | ||
|
||
import java.awt.Component; | ||
import java.io.File; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import javax.swing.event.ChangeListener; | ||
import org.netbeans.gradle.project.GradleProjectConstants; | ||
import org.netbeans.gradle.project.validate.Problem; | ||
import org.netbeans.gradle.project.validate.Validator; | ||
import org.openide.WizardDescriptor; | ||
import org.openide.util.HelpCtx; | ||
|
||
public final class GradleSubProjectConfigPanel implements WizardDescriptor.Panel<WizardDescriptor> { | ||
private final AtomicReference<GradleSingleProjectPropertiesPanel> panel; | ||
private final AtomicReference<GradleSingleProjectConfig> configRef; | ||
|
||
public GradleSubProjectConfigPanel(AtomicReference<GradleSingleProjectConfig> configRef) { | ||
if (configRef == null) throw new NullPointerException("configRef"); | ||
|
||
this.configRef = configRef; | ||
this.panel = new AtomicReference<GradleSingleProjectPropertiesPanel>(); | ||
} | ||
|
||
private GradleSingleProjectPropertiesPanel getPanel() { | ||
GradleSingleProjectPropertiesPanel result = panel.get(); | ||
if (result == null) { | ||
GradleSingleProjectPropertiesPanel newPanel | ||
= new GradleSingleProjectPropertiesPanel(); | ||
if (panel.compareAndSet(null, newPanel)) { | ||
newPanel.addProjectLocationValidator(new Validator<String>() { | ||
private Problem checkFile(File projectDir, String fileName) { | ||
if (!new File(projectDir, fileName).isFile()) { | ||
return Problem.severe(NewProjectStrings.getNotRootProject()); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Problem validateInput(String inputType) { | ||
File rootProject = new File(inputType); | ||
|
||
Problem problem; | ||
|
||
problem = checkFile(rootProject, GradleProjectConstants.BUILD_FILE_NAME); | ||
if (problem != null) { | ||
return problem; | ||
} | ||
|
||
problem = checkFile(rootProject, GradleProjectConstants.SETTINGS_FILE_NAME); | ||
if (problem != null) { | ||
return problem; | ||
} | ||
|
||
problem = checkFile(rootProject, "parent.gradle"); | ||
if (problem != null) { | ||
return problem; | ||
} | ||
return null; | ||
} | ||
}); | ||
} | ||
result = panel.get(); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public Component getComponent() { | ||
return getPanel(); | ||
} | ||
|
||
@Override | ||
public HelpCtx getHelp() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void readSettings(WizardDescriptor settings) { | ||
getPanel().startValidation(); | ||
} | ||
|
||
@Override | ||
public void storeSettings(WizardDescriptor settings) { | ||
configRef.set(getPanel().getConfig()); | ||
} | ||
|
||
@Override | ||
public boolean isValid() { | ||
return getPanel().containsValidData(); | ||
} | ||
|
||
@Override | ||
public void addChangeListener(ChangeListener listener) { | ||
getPanel().addChangeListener(listener); | ||
} | ||
|
||
@Override | ||
public void removeChangeListener(ChangeListener listener) { | ||
getPanel().removeChangeListener(listener); | ||
} | ||
} |
138 changes: 138 additions & 0 deletions
138
src/org/netbeans/gradle/project/newproject/GradleSubProjectWizardIterator.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,138 @@ | ||
package org.netbeans.gradle.project.newproject; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Set; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import javax.swing.event.ChangeListener; | ||
import org.netbeans.api.annotations.common.StaticResource; | ||
import org.netbeans.api.templates.TemplateRegistration; | ||
import org.netbeans.gradle.project.GradleProjectConstants; | ||
import org.netbeans.gradle.project.NbIcons; | ||
import org.netbeans.gradle.project.StringUtils; | ||
import org.openide.WizardDescriptor; | ||
import org.openide.filesystems.FileObject; | ||
import org.openide.filesystems.FileUtil; | ||
import org.openide.util.NbBundle.Messages; | ||
|
||
@TemplateRegistration( | ||
folder="Project/Gradle", | ||
displayName="#template.subGradleProject", | ||
iconBase=NbIcons.PROJECT_ICON_PATH) | ||
@Messages("template.subGradleProject=Gradle Subproject") | ||
public final class GradleSubProjectWizardIterator | ||
implements | ||
WizardDescriptor.BackgroundInstantiatingIterator<WizardDescriptor> { | ||
|
||
@StaticResource | ||
private static final String SINGLE_PROJECT_BUILD_GRADLE = "org/netbeans/gradle/project/resources/newproject/subproject.gradle"; | ||
|
||
private final List<WizardDescriptor.Panel<WizardDescriptor>> descriptors; | ||
private final AtomicReference<GradleSingleProjectConfig> configRef; | ||
private int descriptorIndex; | ||
|
||
public GradleSubProjectWizardIterator() { | ||
this.descriptors = new ArrayList<WizardDescriptor.Panel<WizardDescriptor>>(1); | ||
this.descriptorIndex = 0; | ||
this.configRef = new AtomicReference<GradleSingleProjectConfig>(null); | ||
} | ||
|
||
private static void createBuildGradle( | ||
File projectDir, | ||
GradleSingleProjectConfig config) throws IOException { | ||
String mainClass = config.getMainClass(); | ||
|
||
String buildGradleContent = StringUtils.getResourceAsString( | ||
SINGLE_PROJECT_BUILD_GRADLE, | ||
NewProjectUtils.DEFAULT_FILE_ENCODING); | ||
|
||
buildGradleContent = buildGradleContent.replace("${MAIN_CLASS}", | ||
mainClass != null ? mainClass : ""); | ||
|
||
File buildGradle = new File(projectDir, GradleProjectConstants.BUILD_FILE_NAME); | ||
StringUtils.writeStringToFile(buildGradleContent, NewProjectUtils.DEFAULT_FILE_ENCODING, buildGradle); | ||
} | ||
|
||
@Override | ||
public Set<FileObject> instantiate() throws IOException { | ||
GradleSingleProjectConfig config = configRef.get(); | ||
if (config == null) { | ||
throw new IOException("Missing configuration."); | ||
} | ||
|
||
File projectDirAsFile = FileUtil.normalizeFile(config.getProjectFolder()); | ||
FileObject projectDir = FileUtil.createFolder(projectDirAsFile); | ||
|
||
NewProjectUtils.createDefaultSourceDirs(projectDir); | ||
createBuildGradle(projectDirAsFile, config); | ||
|
||
String mainClass = config.getMainClass(); | ||
if (mainClass != null) { | ||
NewProjectUtils.createMainClass(projectDirAsFile, mainClass); | ||
} | ||
|
||
return Collections.singleton(projectDir); | ||
} | ||
|
||
@Override | ||
public void initialize(WizardDescriptor wizard) { | ||
uninitialize(wizard); | ||
|
||
descriptorIndex = 0; | ||
descriptors.add(new GradleSubProjectConfigPanel(configRef)); | ||
} | ||
|
||
@Override | ||
public void uninitialize(WizardDescriptor wizard) { | ||
descriptors.clear(); | ||
configRef.set(null); | ||
} | ||
|
||
@Override | ||
public WizardDescriptor.Panel<WizardDescriptor> current() { | ||
return descriptors.get(descriptorIndex); | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return "GradleSubProjectTemplate"; | ||
} | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return descriptorIndex < descriptors.size() - 1; | ||
} | ||
|
||
@Override | ||
public boolean hasPrevious() { | ||
return descriptorIndex > 0; | ||
} | ||
|
||
@Override | ||
public void nextPanel() { | ||
if (!hasNext()) { | ||
throw new NoSuchElementException(); | ||
} | ||
descriptorIndex++; | ||
} | ||
|
||
@Override | ||
public void previousPanel() { | ||
if (!hasPrevious()) { | ||
throw new NoSuchElementException(); | ||
} | ||
descriptorIndex--; | ||
} | ||
|
||
@Override | ||
public void addChangeListener(ChangeListener l) { | ||
} | ||
|
||
@Override | ||
public void removeChangeListener(ChangeListener l) { | ||
} | ||
} |
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