blob: 83d14774783e0aef9c5066556ee93b0241a50c44 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*******************************************************************************
* Copyright (c) 2011, 2018 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat - initial API and implementation
************************************************************************/
package org.eclipse.linuxtools.rpm.core;
import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
/**
* Utility class to ease creation of RPM projects.
*
*/
public class RPMProjectCreator {
private RPMProjectLayout layout;
/**
* Creates the utility class and sets the layout that will be used.
*
* @param layout
* The layout of the projects to be created.
*/
public RPMProjectCreator(RPMProjectLayout layout) {
this.layout = layout;
}
/**
* Creates the utility class with the default(RPMBuild) layout.
*/
public RPMProjectCreator() {
this(RPMProjectLayout.RPMBUILD);
}
/**
* Creates a project with the given name in the given location.
*
* @param projectName
* The name of the project.
* @param projectPath
* The parent location of the project.
* @param monitor
* Progress monitor to report back status.
* @return The newly created project.
* @throws CoreException If the location is wrong.
*/
public IProject create(String projectName, IPath projectPath, IProgressMonitor monitor) throws CoreException {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName());
String parsedIPathString = null;
if (!Platform.getLocation().equals(projectPath)) {
parsedIPathString = projectPath.toString().replaceFirst(":/", "://"); //$NON-NLS-1$ //$NON-NLS-2$
try {
description.setLocationURI(new URI(parsedIPathString));
} catch (URISyntaxException e) {
throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID, e.getMessage(), e));
}
}
description.setNatureIds(new String[] { IRPMConstants.RPM_NATURE_ID });
project.create(description, monitor);
monitor.worked(10);
project.open(monitor);
new RPMProject(project, layout);
return project;
}
}
|