Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class DataTransferMessages extends NLS {
public static String WizardProjectsImportPage_projectLabel;
public static String WizardProjectsImportPage_hideExistingProjects;
public static String WizardProjectsImportPage_closeProjectsAfterImport;
public static String WizardProjectsImportPage_skipDotFolders;
public static String WizardProjectsImportPage_invalidProjectName;

// --- Export Wizards ---
Expand Down Expand Up @@ -186,6 +187,7 @@ public class DataTransferMessages extends NLS {
public static String SmartImportWizardPage_selectAtLeastOneFolderToOpenAsProject;
public static String SmartImportWizardPage_showOtherSpecializedImportWizard;
public static String SmartImportWizardPage_closeProjectsAfterImport;
public static String SmartImportWizardPage_skipDotFolders;

public static String SmartImportJob_discardRootProject_title;
public static String SmartImportJob_discardRootProject_description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Set<File> findConfigurableLocations(File root, IProgressMonitor monitor)
Set<File> projectFiles = new LinkedHashSet<>();
Set<String> visitedDirectories = new HashSet<>();
WizardProjectsImportPage.collectProjectFilesFromDirectory(projectFiles, root, visitedDirectories, true,
monitor);
false, monitor);
Set<File> res = new LinkedHashSet<>();
for (File projectFile : projectFiles) {
res.add(projectFile.getParentFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SmartImportJob extends Job {
private boolean deepChildrenDetection;
private final boolean configureProjects;
private boolean closeProjectsAfterImport;
private boolean skipDotFolders = true;
private boolean reconfigureEclipseProjects;
private IWorkingSet[] workingSets;

Expand Down Expand Up @@ -347,6 +348,9 @@ private Set<IProject> searchAndImportChildrenProjectsRecursively(final IContaine
final Set<IProject> res = Collections.synchronizedSet(new HashSet<>());
for (IResource childResource : parentContainer.members()) {
if (childResource.getType() == IResource.FOLDER && !childResource.isDerived()) {
if (skipDotFolders && childResource.getName().startsWith(".")) { //$NON-NLS-1$
continue;
}
IPath location = childResource.getLocation();
if (location == null) {
continue;
Expand Down Expand Up @@ -530,6 +534,18 @@ private Set<IPath> toPathSet(Set<? extends IContainer> resources) {
return res;
}

private static boolean isInsideDotFolder(File file) {
File current = file;
while (current != null) {
String name = current.getName();
if (!name.isEmpty() && name.startsWith(".")) { //$NON-NLS-1$
return true;
}
current = current.getParentFile();
}
return false;
}

/**
* @param refreshMode One {@link IResource#BACKGROUND_REFRESH} for background refresh, or {@link IResource#NONE} for immediate refresh
*/
Expand Down Expand Up @@ -684,6 +700,9 @@ public Map<File, List<ProjectConfigurator>> getImportProposals(IProgressMonitor
for (ProjectConfigurator configurator : activeConfigurators) {
configurator.removeDirtyDirectories(res);
}
if (this.skipDotFolders) {
res.keySet().removeIf(SmartImportJob::isInsideDotFolder);
}
this.importProposals = res;
}
return this.importProposals;
Expand Down Expand Up @@ -723,6 +742,22 @@ void setCloseProjectsAfterImport(boolean closeProjectsAfterImport) {
this.closeProjectsAfterImport = closeProjectsAfterImport;
}

/**
* @param skipDotFolders
* if true, folders starting with '.' (e.g. .git) are skipped
* during project scanning
*/
void setSkipDotFolders(boolean skipDotFolders) {
this.skipDotFolders = skipDotFolders;
}

/**
* @return whether folders starting with '.' are skipped during scanning
*/
public boolean isSkipDotFolders() {
return this.skipDotFolders;
}

/**
* Forget the initial import proposals.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ public class SmartImportRootWizardPage extends WizardPage {

private static final String STORE_CONFIGURE_NATURES = "SmartImportRootWizardPage.STORE_CONFIGURE_NATURES"; //$NON-NLS-1$

private static final String STORE_SKIP_DOT_FOLDERS = "SmartImportRootWizardPage.STORE_SKIP_DOT_FOLDERS"; //$NON-NLS-1$

// Root
private File selection;
private Combo rootDirectoryText;
Expand All @@ -135,6 +137,7 @@ public class SmartImportRootWizardPage extends WizardPage {
private boolean closeProjectsAfterImport = false;
private boolean detectNestedProjects = true;
private boolean configureProjects = true;
private boolean skipDotFolders = true;
// Working sets
private Set<IWorkingSet> workingSets;
private WorkingSetGroup workingSetsGroup;
Expand Down Expand Up @@ -475,6 +478,19 @@ public void widgetSelected(SelectionEvent e) {
* Creates the UI elements for the import options
*/
private void createConfigurationOptions(Composite parent) {
GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1);
final Button skipDotFoldersCheckbox = new Button(parent, SWT.CHECK);
skipDotFoldersCheckbox.setText(DataTransferMessages.SmartImportWizardPage_skipDotFolders);
skipDotFoldersCheckbox.setLayoutData(layoutData);
skipDotFoldersCheckbox.setSelection(this.skipDotFolders);
skipDotFoldersCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SmartImportRootWizardPage.this.skipDotFolders = skipDotFoldersCheckbox.getSelection();
refreshProposals();
}
});

Button closeProjectsCheckbox = new Button(parent, SWT.CHECK);
closeProjectsCheckbox.setText(DataTransferMessages.SmartImportWizardPage_closeProjectsAfterImport);
closeProjectsCheckbox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
Expand Down Expand Up @@ -508,10 +524,9 @@ public void widgetSelected(SelectionEvent e) {
DataTransferMessages.SmartImportWizardPage_availableDetectors_title, message.toString());
}
});
GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1);
final Button detectNestedProjectsCheckbox = new Button(parent, SWT.CHECK);
detectNestedProjectsCheckbox.setText(DataTransferMessages.SmartImportWizardPage_detectNestedProjects);
detectNestedProjectsCheckbox.setLayoutData(layoutData);
detectNestedProjectsCheckbox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
detectNestedProjectsCheckbox.setSelection(this.detectNestedProjects);
detectNestedProjectsCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
Expand All @@ -523,7 +538,7 @@ public void widgetSelected(SelectionEvent e) {

final Button configureProjectsCheckbox = new Button(parent, SWT.CHECK);
configureProjectsCheckbox.setText(DataTransferMessages.SmartImportWizardPage_configureProjects);
configureProjectsCheckbox.setLayoutData(layoutData);
configureProjectsCheckbox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
configureProjectsCheckbox.setSelection(this.configureProjects);
configureProjectsCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
Expand Down Expand Up @@ -825,6 +840,13 @@ boolean isCloseProjectsAfterImport() {
return closeProjectsAfterImport;
}

/**
* @return whether folders starting with '.' should be skipped during scanning
*/
boolean isSkipDotFolders() {
return skipDotFolders;
}

private void refreshProposals() {
stopAndDisconnectCurrentWork();
this.potentialProjects = Collections.emptyMap();
Expand Down Expand Up @@ -956,6 +978,9 @@ private void loadWidgetStates() {
closeProjectsAfterImport = dialogSettings.getBoolean(STORE_CLOSE_IMPORTED);
detectNestedProjects = dialogSettings.getBoolean(STORE_NESTED_PROJECTS);
configureProjects = dialogSettings.getBoolean(STORE_CONFIGURE_NATURES);
if (dialogSettings.get(STORE_SKIP_DOT_FOLDERS) != null) {
skipDotFolders = dialogSettings.getBoolean(STORE_SKIP_DOT_FOLDERS);
}
}
}

Expand All @@ -969,6 +994,7 @@ private void saveWidgetStates() {
dialogSettings.put(STORE_CLOSE_IMPORTED, closeProjectsAfterImport);
dialogSettings.put(STORE_NESTED_PROJECTS, detectNestedProjects);
dialogSettings.put(STORE_CONFIGURE_NATURES, configureProjects);
dialogSettings.put(STORE_SKIP_DOT_FOLDERS, skipDotFolders);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public SmartImportJob createOrGetConfiguredImportJob() {
// WS change automatically
this.easymportJob.setWorkingSets(projectRootPage.getSelectedWorkingSets());
this.easymportJob.setCloseProjectsAfterImport(projectRootPage.isCloseProjectsAfterImport());
this.easymportJob.setSkipDotFolders(projectRootPage.isSkipDotFolders());

return this.easymportJob;
}
Expand Down Expand Up @@ -337,7 +338,8 @@ private static boolean matchesPage(SmartImportJob job, SmartImportRootWizardPage
boolean sameSource = jobRoot.equals(pageRoot)
|| (isValidArchive(pageRoot) && getExpandDirectory(pageRoot).getAbsoluteFile().equals(jobRoot));
return sameSource && job.isDetectNestedProjects() == page.isDetectNestedProject()
&& job.isConfigureProjects() == page.isConfigureProjects();
&& job.isConfigureProjects() == page.isConfigureProjects()
&& job.isSkipDotFolders() == page.isSkipDotFolders();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ public boolean select(Viewer viewer, Object parentElement,

private static final String STORE_ARCHIVE_SELECTED = "WizardProjectsImportPage.STORE_ARCHIVE_SELECTED"; //$NON-NLS-1$

private static final String STORE_SKIP_DOT_FOLDERS = "WizardProjectsImportPage.STORE_SKIP_DOT_FOLDERS"; //$NON-NLS-1$

private Combo directoryPathField;

private CheckboxTreeViewer projectsList;
Expand All @@ -341,6 +343,10 @@ public boolean select(Viewer viewer, Object parentElement,

private boolean hideConflictingProjects = false;

private Button skipDotFoldersCheckbox;

private boolean skipDotFolders = true;

private ProjectRecord[] selectedProjects = new ProjectRecord[0];

// Keep track of the directory that we browsed to last time
Expand Down Expand Up @@ -505,6 +511,22 @@ public void widgetSelected(SelectionEvent e) {
}
}));
Dialog.applyDialogFont(hideConflictingProjectsCheckbox);

skipDotFoldersCheckbox = new Button(optionsGroup, SWT.CHECK);
skipDotFoldersCheckbox.setText(DataTransferMessages.WizardProjectsImportPage_skipDotFolders);
skipDotFoldersCheckbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
skipDotFoldersCheckbox.setSelection(skipDotFolders);
skipDotFoldersCheckbox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
skipDotFolders = skipDotFoldersCheckbox.getSelection();
if (projectFromDirectoryRadio.getSelection()) {
updateProjectsListAndPreventFocusLostHandling(directoryPathField.getText().trim(), true);
} else {
updateProjectsListAndPreventFocusLostHandling(archivePathField.getText().trim(), true);
}
}
});
}

/**
Expand Down Expand Up @@ -940,7 +962,7 @@ else if (dirSelected && directory.isDirectory()) {

Collection<File> files = new ArrayList<>();
if (!collectProjectFilesFromDirectory(files, directory,
null, nestedProjects, monitor)) {
null, nestedProjects, skipDotFolders, monitor)) {
return;
}
Iterator<File> filesIterator3 = files.iterator();
Expand Down Expand Up @@ -1064,12 +1086,14 @@ private TarFile getSpecifiedTarSourceFile(String fileName) {
* Set of canonical paths of directories, used as recursion guard
* @param nestedProjects
* whether to look for nested projects
* @param skipDotFolders
* whether to skip folders starting with '.' (e.g. .git)
* @param monitor
* The monitor to report to
* @return boolean <code>true</code> if the operation was completed.
*/
static boolean collectProjectFilesFromDirectory(Collection<File> files, File directory,
Set<String> directoriesVisited, boolean nestedProjects, IProgressMonitor monitor) {
Set<String> directoriesVisited, boolean nestedProjects, boolean skipDotFolders, IProgressMonitor monitor) {

if (monitor.isCanceled()) {
return false;
Expand Down Expand Up @@ -1110,20 +1134,24 @@ static boolean collectProjectFilesFromDirectory(Collection<File> files, File dir
// no project description found or search for nested projects enabled,
// so recurse into sub-directories
for (File dir : directories) {
if (!dir.getName().equals(METADATA_FOLDER)) {
try {
String canonicalPath = dir.getCanonicalPath();
if (!directoriesVisited.add(canonicalPath)) {
// already been here --> do not recurse
continue;
}
} catch (IOException exception) {
StatusManager.getManager().handle(StatusUtil.newError(exception));

if (dir.getName().equals(METADATA_FOLDER)) {
continue;
}
if (skipDotFolders && dir.getName().startsWith(".")) { //$NON-NLS-1$
continue;
}
try {
String canonicalPath = dir.getCanonicalPath();
if (!directoriesVisited.add(canonicalPath)) {
// already been here --> do not recurse
continue;
}
collectProjectFilesFromDirectory(files, dir,
directoriesVisited, nestedProjects, monitor);
} catch (IOException exception) {
StatusManager.getManager().handle(StatusUtil.newError(exception));

}
collectProjectFilesFromDirectory(files, dir,
directoriesVisited, nestedProjects, skipDotFolders, monitor);
}
return true;
}
Expand Down Expand Up @@ -1565,6 +1593,12 @@ public void restoreWidgetValues() {
// trigger a selection event for the button to make sure the filter is set
// properly at page creation
hideConflictingProjectsCheckbox.notifyListeners(SWT.Selection, new Event());

// checkbox
if (settings.get(STORE_SKIP_DOT_FOLDERS) != null) {
skipDotFolders = settings.getBoolean(STORE_SKIP_DOT_FOLDERS);
}
skipDotFoldersCheckbox.setSelection(skipDotFolders);
}

// Second, check to see if we don't have an initial path,
Expand Down Expand Up @@ -1644,6 +1678,8 @@ public void saveWidgetValues() {
settings.put(STORE_CLOSE_CREATED_PROJECTS_ID, closeProjectsCheckbox.getSelection());

settings.put(STORE_HIDE_CONFLICTING_PROJECTS_ID, hideConflictingProjectsCheckbox.getSelection());

settings.put(STORE_SKIP_DOT_FOLDERS, skipDotFoldersCheckbox.getSelection());
}
}

Expand Down Expand Up @@ -1674,6 +1710,15 @@ public Button getNestedProjectsCheckbox() {
return nestedProjectsCheckbox;
}

/**
* Method used for test suite.
*
* @return Button skip dot folders checkbox
*/
public Button getSkipDotFoldersCheckbox() {
return skipDotFoldersCheckbox;
}

@Override
public void handleEvent(Event event) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ WizardProjectsImportPage_invalidProjectName=Invalid Project
WizardProjectsImportPage_projectLabel={0} ({1})
WizardProjectsImportPage_hideExistingProjects=H&ide projects that already exist in the workspace
WizardProjectsImportPage_closeProjectsAfterImport=Cl&ose newly imported projects upon completion
WizardProjectsImportPage_skipDotFolders=S&kip folders starting with '.' (e.g. .git)

# --- Export Wizards ---
DataTransfer_export = Export
Expand Down Expand Up @@ -213,4 +214,5 @@ SmartImportWizardPage_incompleteExpand_title=Incomplete expansion
SmartImportWizardPage_incompleteExpand_message=Archive expansion didn''t complete successfully. It''s recommend that you clean directory {0} and try importing again.
SmartImportWizardPage_selectAtLeastOneFolderToOpenAsProject=Select at least one folder to import as project.
SmartImportWizardPage_showOtherSpecializedImportWizard=Show other specialized import wizards
SmartImportWizardPage_closeProjectsAfterImport=Cl&ose newly imported projects upon completion
SmartImportWizardPage_closeProjectsAfterImport=Cl&ose newly imported projects upon completion
SmartImportWizardPage_skipDotFolders=S&kip folders starting with '.' (e.g. .git)
Loading
Loading