Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 633de37894534761c60d1d9b96dfc00f6ed2aa22 (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
/*******************************************************************************
 * Copyright (c) 2013 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Neil Guzman - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.createrepo;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;
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.Platform;

/**
 * Utility class to help create a createrepo project.
 */
public final class CreaterepoProjectCreator {

    private CreaterepoProjectCreator() {}

    /**
     * Create a createrepo project given a project name and the progress
     * monitor. The new project will contain an empty repodata folder.
     *
     * @param projectName The name of the project.
     * @param locationPath The location path of the project
     * @param monitor The progress monitor.
     * @return The newly created project.
     * @throws CoreException Thrown when creating a project fails.
     */
    public static IProject create(String projectName, IPath locationPath,
            String repoName, IProgressMonitor monitor) throws CoreException {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IProject project = root.getProject(projectName);
        IProjectDescription description = ResourcesPlugin.getWorkspace()
                .newProjectDescription(projectName);
        if (!Platform.getLocation().equals(locationPath)) {
            description.setLocation(locationPath);
        }
        description.setNatureIds(new String[] {CreaterepoProjectNature.CREATEREPO_NATURE_ID});
        project.create(description, monitor);
        project.open(monitor);
        IFile repoFile = project.getFile(repoName);
        InputStream stream = new ByteArrayInputStream(ICreaterepoConstants.EMPTY_STRING.getBytes());
        if (!repoFile.exists()) {
            repoFile.create(stream, true, monitor);
        }
        return project;
    }

}

Back to the top