Exemplo n.º 1
0
        //PROJECT_LOCATION_FIRST
        //PROJECT_NAME
        public static void CreateProject(FeatureSelection selection)
        {
            switch (selection.ProjectType)
            {
            case FeatureSelection.ProjectTypes.Ant:
                Write("build.xml", GetStringResource("PosGen.res.build.xml"), selection);
                Write("manifest.mf", GetStringResource("PosGen.res.manifest.mf"), selection);
                Write("nbproject/build-impl.xml", GetStringResource("PosGen.res.build-impl.xml"), selection);
                Write("nbproject/project.properties", GetStringResource("PosGen.res.project.properties"),
                      selection);
                Write("nbproject/project.xml", GetStringResource("PosGen.res.project.xml"), selection);
                Write("nbproject/private/private.properties", GetStringResource("PosGen.res.private.properties"),
                      selection);

                var srcPath = Path.Combine(
                    selection.ProjectLocation,
                    "src",
                    selection.PackageName.Replace('.', Path.DirectorySeparatorChar)
                    );

                Directory.CreateDirectory(srcPath);
                Directory.CreateDirectory(Path.Combine(selection.ProjectLocation, "test"));

                File.WriteAllText(Path.Combine(srcPath, "Main.java"),
                                  GetStringResource(selection.InsertCliGui ? "PosGen.res.CLIMain.java" : "PosGen.res.Main.java")
                                  .Replace("{{PACKAGE_NAME}}", selection.PackageName)
                                  .Replace("{{PROJECT_NAME}}", selection.ProjectName));

                if (selection.InsertCliGui)
                {
                    File.AppendAllText(Path.Combine(selection.ProjectLocation, "nbproject/project.properties"),
                                       @"\" + Environment.NewLine + @"${file.reference.CLIGui.jar}" + Environment.NewLine +
                                       @"file.reference.CLIGui.jar=libs\\CLIGui.jar");
                    Directory.CreateDirectory(Path.Combine(selection.ProjectLocation, "libs", "CopyLibs"));
                    Write("libs/nblibraries.properties", GetStringResource("PosGen.res.nblibraries.properties"),
                          selection);

                    File.WriteAllBytes(Path.Combine(Path.Combine(selection.ProjectLocation, "libs", "CLIGui.jar")),
                                       GetBinaryResource("PosGen.res.CLIGui.jar"));
                    File.WriteAllBytes(
                        Path.Combine(Path.Combine(selection.ProjectLocation, "libs", "CopyLibs",
                                                  "org-netbeans-modules-java-j2seproject-copylibstask.jar")),
                        GetBinaryResource("PosGen.res.copylibs.jar"));
                }

                break;

            case FeatureSelection.ProjectTypes.Maven:
                throw new NotImplementedException();

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 2
0
        private static void Write(string path, string content, FeatureSelection selection)
        {
            var filePath = Path.Combine(selection.ProjectLocation, path);

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            var directoryName = Path.GetDirectoryName(selection.ProjectLocation).Split(Path.DirectorySeparatorChar)
                                .Last();

            File.WriteAllText(filePath,
                              content.Replace("{{PROJECT_NAME}}", selection.ProjectName)
                              .Replace("{{PROJECT_LOCATION_FIRST}}", directoryName)
                              .Replace("{{PACKAGE_NAME}}", selection.PackageName));
        }
Exemplo n.º 3
0
        //TODO: if maven: group id
        //TODO: setup junit4
        private static FeatureSelection InputFeatures()
        {
            //Print POSGEN banner
            Console.WriteLine(strings.banner);

            string projectName;
            string projectLocation;
            string projectType;
            string packageName;
            string insertCliGui;

            var valid = false;

            do
            {
                #region projectName

                do
                {
                    Console.Write("Name of the project: ");
                    projectName = Console.ReadLine();

                    Debug.Assert(projectName != null, nameof(projectName) + " != null");
                    valid = projectName.Length > 0;
                } while (!valid);

                #endregion

                #region projectLocation

                do
                {
                    Console.Write("Project location(./" + ToKebabCase(projectName) + "/): ");
                    projectLocation = Console.ReadLine();

                    Debug.Assert(projectLocation != null, nameof(projectLocation) + " != null");
                    if (projectLocation.Length < 1)
                    {
                        projectLocation = ToKebabCase(projectName);
                    }

                    valid = projectLocation.Length > 0;
                } while (!valid);

                #endregion

                #region projectType

                do
                {
                    Console.Write("Project type(ANT, maven): ");
                    projectType = Console.ReadLine();

                    Debug.Assert(projectType != null, nameof(projectType) + " != null");
                    switch (projectType.ToLower())
                    {
                    case "ant":
                    case "maven":
                        valid = true;
                        break;

                    default:
                        valid = false;
                        break;
                    }

                    projectType = projectType.ToLower();
                } while (!valid);

                #endregion

                #region packageName

                do
                {
                    Console.Write("Name of the package: ");
                    packageName = Console.ReadLine();

                    Debug.Assert(projectName != null, nameof(projectName) + " != null");
                    valid = projectName.Length > 0;
                } while (!valid);

                #endregion

                #region insertCliGui

                do
                {
                    Console.Write("Insert CLIGui(Y, n): ");
                    insertCliGui = Console.ReadLine();

                    Debug.Assert(insertCliGui != null, nameof(insertCliGui) + " != null");
                    switch (insertCliGui.ToLower())
                    {
                    case "y":
                    case "n":
                        valid = true;
                        break;

                    default:
                        valid = false;
                        break;
                    }

                    insertCliGui = insertCliGui.ToLower();
                } while (!valid);

                #endregion

                #region confirmed

                Console.WriteLine("\n\nProject name: " + projectName + "\nProject location: " + projectLocation +
                                  "\nProject type: " + projectType + "\nInsert CLIGui: " + insertCliGui);
                string confirmed;
                do
                {
                    Console.Write("Is this information correct(Y, n):");
                    confirmed = Console.ReadLine();

                    Debug.Assert(confirmed != null, nameof(confirmed) + " != null");
                    switch (confirmed.ToLower())
                    {
                    case "y":
                    case "n":
                        valid = true;
                        break;

                    default:
                        valid = false;
                        break;
                    }

                    confirmed = confirmed.ToLower();
                } while (!valid);

                #endregion

                valid = confirmed.Contains("y");
            } while (!valid);

            return(FeatureSelection.Of(projectName, projectLocation, projectType, packageName, insertCliGui));
        }