如何管理非托管 Eclipse 格式化配置文件?

发布于 2024-10-21 04:57:35 字数 139 浏览 1 评论 0原文

我们的项目有一个“非托管配置文件”和节省时间的自动格式化。我希望能够修改此非托管配置文件的设置,并能够将它们重新签入版本控制。

Eclipse 的帮助文档非常没有帮助(“您不允许更改这样的配置文件,只有配置文件的创建者(管理员)可以更改它。”)。

Our project has an "Unmanaged profile" and save-time autoformatting. I'd like to be able to modify the settings for this unmanaged profile and be able to check them back in to version control.

Eclipse's help documents are quite unhelpful ("You are not allowed to change such a profile, only the creator (manager) of the profile can change it.").

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年 2024-10-28 04:57:35

我不确定这是否允许您将您的配置文件重新签入版本控制,但以下过程将允许您在任何已签出源的计算机上编辑您的配置文件。

要编辑您的配置文件,您必须在 Eclipse 中重新创建配置文件,您可以轻松地执行以下操作:

  • 通过单击“新建...”创建新配置文件
  • 为新配置文件指定与现有非托管配置文件相同的名称。
  • 单击“确定”之前,请确保您在“使用以下配置文件初始化设置”下拉列表中选择了非托管配置文件。

这将允许您重新创建配置文件,并允许您像平常一样在 Eclipse 中修改它。

注意:此过程适用于 Eclipse Indigo

I'm not sure if this will allow you to check your profile back in to version control, but the following process will allow you to edit your profile on any computer that has the source checked out.

To edit your profile, you have to recreate the profile in Eclipse, which you can easily do as follows:

  • Create a new profile by clicking "New..."
  • Give the new profile the same name as your existing unmanaged profile.
  • Before clicking OK, make sure you selected your unmanaged profile in "Initialize settings with the following profile" drop down list.

This will let you recreate the profile, and allow you to modify it in Eclipse, as normal.

Note: This process works with Eclipse Indigo

攒眉千度 2024-10-28 04:57:35

问题是托管配置文件实际上存储在您的工作区而不是您的项目中。当您进行项目特定更改(例如选择不同的配置文件)时,设置将被推送到您的项目中。但项目中的设置与配置文件(工作区)中的设置格式不同。

目前 eclipse 不具备反向执行此操作的能力。也就是说,它无法从项目文件夹中获取设置来在工作区中创建配置文件。实际上,“非托管配置文件”是您丢失了源代码的配置文件。

我发现对配置文件进行逆向工程的最简单方法是生成一个可以导入的 XML 配置文件(在格式化程序设置 --> 导入按钮下)。

对项目的设置进行逆向工程;我写了下面的程序。它从项目文件夹中读取设置并将其作为 XML 文件写出:

import java.io.*;



public class ExtractFormatter {

    public static void main( String args[] ) throws IOException {
        if (args.length < 2)
            throw new RuntimeException("No arguements specified; expected <project folder> <output file>");

        File inFile = new File(args[0]);
        File outFile = new File(args[1]);

        BufferedReader reader = new BufferedReader(new FileReader(new File(inFile,
                ".settings/org.eclipse.jdt.core.prefs")));
        PrintWriter writer = new PrintWriter(outFile);
        writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");

        // Retain the date from the file as a comment
        String line = reader.readLine();
        writer.println("<!-- Exported from " + inFile + " -->");
        writer.println("<!-- " + line + " -->");

        writer.println("<profiles version=\"12\">");
        writer.println("<profile kind=\"CodeFormatterProfile\" name=\"" + inFile.getName()
                + "\" version=\"12\">\")");


        // Now read every setting for the formatter and write it out as an XML tag.
        for (line = reader.readLine(); line != null; line = reader.readLine()) {
            if (line.startsWith("org.eclipse.jdt.core.formatter.")) {
                String[] parts = line.split("=", 2);
                writer.println("<setting id=\"" + parts[0] + "\" value=\"" + parts[1] + "\" />");
            }
        }

        writer.println("</profile>");
        writer.println("</profiles>");

        reader.close();
        writer.close();
    }
}

The problem is that a managed profile is actually stored in your workspace not your project. Settings are pushed into your project when you make project specific changes such as selecting a different profile. But the settings in the project are a different format to those in in the profile (in the workspace).

At present eclipse does not have the ability to perform this in reverse. That is it can't take settings from your project folder to create a profile in the workspace. Effectively an "Unmanaged Profile" is a profile to which you have lost the source code.

The simplest way I've found to reverse-engineer the profile is to generate an XML profile file that can be imported (under the formatter settings --> import button).

To reverse-engineer the the settings from a project; I wrote the following program. It reads the settings from a project folder and writes them out as an XML file:

import java.io.*;



public class ExtractFormatter {

    public static void main( String args[] ) throws IOException {
        if (args.length < 2)
            throw new RuntimeException("No arguements specified; expected <project folder> <output file>");

        File inFile = new File(args[0]);
        File outFile = new File(args[1]);

        BufferedReader reader = new BufferedReader(new FileReader(new File(inFile,
                ".settings/org.eclipse.jdt.core.prefs")));
        PrintWriter writer = new PrintWriter(outFile);
        writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");

        // Retain the date from the file as a comment
        String line = reader.readLine();
        writer.println("<!-- Exported from " + inFile + " -->");
        writer.println("<!-- " + line + " -->");

        writer.println("<profiles version=\"12\">");
        writer.println("<profile kind=\"CodeFormatterProfile\" name=\"" + inFile.getName()
                + "\" version=\"12\">\")");


        // Now read every setting for the formatter and write it out as an XML tag.
        for (line = reader.readLine(); line != null; line = reader.readLine()) {
            if (line.startsWith("org.eclipse.jdt.core.formatter.")) {
                String[] parts = line.split("=", 2);
                writer.println("<setting id=\"" + parts[0] + "\" value=\"" + parts[1] + "\" />");
            }
        }

        writer.println("</profile>");
        writer.println("</profiles>");

        reader.close();
        writer.close();
    }
}
捶死心动 2024-10-28 04:57:35

当您有非托管配置文件时,Eclipse 应该在您的项目目录中放置一个 .settings 文件夹。到目前为止,我发现更改设置的唯一方法是进入项目内的 .settings 文件夹并手动编辑其中的 .prefs 文件。

Eclipse should put a .settings folder in your project dir when you have an unmanaged profile. The only way I've found to change the settings so far is to go into the .settings folder within the project and hand edit the .prefs files in there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文